1

I'm using Jquery to submit a form. I want to loop through the form after the user clicks on a submit button to get the select option. There are many different select fields. The select options are generated using PHP.

A sample of the HTML:

<select id="selectHome_1">
 <option></option>
</select>

<select id="selectHome_2">
  <option></option>
</select>

<inpupt type="submit" id="update" />

The JQuery

$("#update").click(function() {        
   //Loop through all select fields
   $("input[id^='selectHome_']").each(function(){
  //Production code will do other things        
     alert('test');//Test to see if it works...
   });
});

The code that searches for id=selectHome_ is not working (the alert box never shows).

Any ideas would be greatly appreciated.

Cheers!

2 Answers 2

3

You forgot your : infront of input:

$(":input[id^='selectHome_']").each();

http://api.jquery.com/input-selector/

Sign up to request clarification or add additional context in comments.

Comments

2

use

$("select[id^='selectHome_']")

and test with

alert($("select[id^='selectHome_']").length)

2 Comments

+1 Excellent. Much better now :) Thank you for handling correction in such a good way.
Thanks for the tip on testing by checking the length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.