Javascript – Collecting user input to use as query with API

formsjavascriptjqueryuser interface

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.

Best Answer

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.

Related Topic