Matt
Matt

Reputation: 7212

Jquery loop after click

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!

Upvotes: 1

Views: 253

Answers (2)

parserr
parserr

Reputation: 729

use

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

and test with

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

Upvotes: 2

Sampson
Sampson

Reputation: 268344

You forgot your : infront of input:

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

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

Upvotes: 3

Related Questions