0

I am trying to get the second javascript line in this example to work (being able to select the check box from javascript): http://jsfiddle.net/eTvDB/

Essentially, if I don't use xxx[] form for the name, I won't be able to obtain an array in PHP. Any ideas?

Thanks.

1
  • Well elements["select2[]"].options[0] doesn't make sense when select2[] is the name of some checkboxes and not the name of a select element. If the idea is to check the first checkbox with that name document.forms["myForm"].elements["select2[]"][0].checked=true; works. If the idea is to check all of that name there are other ways to do it... Commented Aug 21, 2012 at 2:02

1 Answer 1

3

Use:

document.myForm['select2[]'][0].checked = true;

Or

document.getElementsByName('select2[]')[0].checked = true;

The demo.

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

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.