views:

78

answers:

2

Hi,

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!

+3  A: 

You forgot your : infront of input:

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

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

Jonathan Sampson
A typo. Oops! Thanks! :)
Matt
+2  A: 

use

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

and test with

alert($("select[id^='selectHome_']").length)
parserr
noticed after submitting.. corrected, thx. :)
parserr
+1 Excellent. Much better now :) Thank you for handling correction in such a good way.
Jonathan Sampson
Thanks for the tip on testing by checking the length.
Matt