0

My html code is

<select id="child[1]" name="child[1]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select id="child[2]" name="child[2]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

My JS code not working

JS code is

alert(jQuery("#child").length);

Can you please help me how can I get the child array, I want to send the array through AJAX

1
  • alert(jQuery("#child[1]").length); Commented Mar 2, 2012 at 12:17

2 Answers 2

1

change your jquery selector to

jQuery("[name*=child\\[]")
Sign up to request clarification or add additional context in comments.

Comments

0
jQuery("select[name^=child]").serializeArray()

what this does is:

  1. get select elements that have a name that starts with "child"
  2. serializes them into an array

the output is something like:

[
    {name:'child[1]', value:'1'},
    {name:'child[2]', value:'1'}
]

http://jsfiddle.net/qdK7V/1/

Comments

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.