2

I'm attempting to collect the user's input and execute a search using an API. At this point, I can use the API (ebay search) by typing keywords into the html document- but I want the user to be able to type the keywords for searching. I created a simple modal with a form containing text input and a submit button. I gave the input an id of ="searchobject," so I can retrieve the user input by id. What I can't figure out is how to use the Submit button to push the user input to where I would put the keywords. Then the page should show the results of the users input.

0

I realized you may be in this category. Make sure you read the Open letter to students with homework problems before making further posts. I tried to follow the rules in there for answering this, because i'm already starting to have flashbacks to CSC101.

---Original Answer---

There's a few steps you'll need to take to do this.

1) Hook onto the event that the button generates. < button onclick="myFunction()" > Click me < /button >

2) In a function called myFunction() (within a code tag) you'll need to provide the javascript/jquery to act on the event. In this case, this is where you'll get the contents of the textbox and then provide the logic for performing the request to Ebay's API: < code> function myFunction(){ //Provide what you want to do in response to the button click here. } < /code>

3) Complete the request and show output. Once the request is done, you'll need to use some jQuery/javascript to modify the page to show results. Most commonly, you'll have a paragraph tag or something with an id that you want to get at to modify it.

  • So, I can add a functionality whereby onclick will save the input in a function and then I can then collect the input by calling the function within a code tag? Am I understanding this correctly? – Frederick John Sep 21 '16 at 18:14
  • More or less. Read up on what object is returned when you make a request. You'll have to use the information in that object to print out the information. From your question, it appeared that you were already doing this to some extent - i took it to mean you were loading the page, and when it loaded displaying the results of the search. – Adam Wells Sep 21 '16 at 18:16
  • When the page loads the modal pops up. If I can successfully get the search to be dependent on the user input will it refresh the page? Because in doing so will cause another modal to pop up. I just realized this could be in an issue. – Frederick John Sep 21 '16 at 18:19
  • This isn't a homework question it's a real life scenario... I am a very new programmer and I believe I have all of the pieces but am struggling to put them together. My question is one that needs both high and low level explanations. – Frederick John Sep 21 '16 at 18:24
  • Running JQuery on a particular tag doesn't cause a reload. You actually physically go in and change the displayed information on the page. Think of it a little like putting a patch on a pair of jeans. I don't have to remake the jeans entirely when i put a patch on them. w3schools.com/js/js_input_examples.asp has examples for similar things on it. Play with those a bit – Adam Wells Sep 21 '16 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.