Edward
Edward

Reputation: 3081

Jquerying using child selectors

I have a div being populated from PHP i'm trying to bind all the input boxes in a div to variables, (I do not wish to use serialize) how can I use Jquery to select each one and bind it to a variable such as

var location_id = $('#Wednesday').find('input').nth-child(0);
var static_id  =$('#Wednesday').find('input').nth-child(1);

something of that nature thanks!

<div id='Wednesday' class='ui-widget-content ui-state-default' name='' value=''>  ";

echo "<input name='".$day."_".$locationid."_locationID' value='".$locationid."'  type='hidden'> ";
echo "<input name='".$day."_".$locationid."_static' value='".$static."'  type='hidden'> ";
echo "<input name='".$day."_".$locationid."_primary' value='".$first_always."' type='hidden'> ";
echo "<input name='".$day."_".$locationid."_all_locations' value='".$all_locations."' type='hidden'> ";

</div>

Upvotes: 0

Views: 39

Answers (3)

Mike Brant
Mike Brant

Reputation: 71424

As a side note (since you already have your answer), any time I see input names of a form similar to what you have:

'name="' . $day . '_' . $location_id . '_locationID"'

It screams out to me that this might be a case where you should be using array-style form inputs like this:

'name="locationID[' . $day . '][' . $location_id . ']"'

That way in PHP, you already have a nice array built for you in $_POST and you don't need to explode() to build arrays out of all the input fields.

Upvotes: 1

Joseph Silber
Joseph Silber

Reputation: 220066

var inputs = $('#Wednesday').find('input');

var location_id = inputs.eq(0).val();
var static_id  = inputs.eq(1).val();

Upvotes: 1

Explosion Pills
Explosion Pills

Reputation: 191789

Use .eq instead of .nth-child().

Upvotes: 0

Related Questions