javascript - How to pass the value of an option field as well as an input box via post in jquery/PHP?

604

I have a search bar like

<div id="searchbar">
<form>
<select name="Cars">
<option value="big">Big Cars</option>
<option value="small">Small Cars</option>
</select>
<input type ='text' name="searchkey" id ="search" onblur ='setTimeout('removeSearchSuggestions()', 20);' onkeyup ='getSearchSuggestions(this.value);'/>
&nbsp;
<br/>
<div id = 'searchsuggest'></div>
<input type ='submit' value = 'Search' />
</form>
</div>

and i have the following jquery code snippet

function getSearchSuggestions(value){
   if (value !=""){
   $.post("searchSuggest.php", {searchPart:value}, function(data) {
     $("#searchsuggest").html(data);
     doSearchCSS();
   });
   } else {
    removeSearchSuggestions();
    }

  }

So searchSuggest has access to "searchPart" i.e. the value that is typed into the input box. I am modifying something I got to work for a case without options. How do I modify the jquery function to access the selected option in searchSuggest.php?

Thanks!

967

Answer

Solution:

This will help you: http://api.jquery.com/selected-selector/

People are also looking for solutions to the problem: php - How to change attribute value on a simpleXML element?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.