Multiple radio's with same names & predefined key value

J

João Morais

I there guys,

I have something like this:

<input type="radio" name="options[10]" value="1" />
<input type="radio" name="options[10]" value="2" />
<input type="radio" name="options[10]" value="3" />

<input type="radio" name="options[23]" value="9" />
<input type="radio" name="options[23]" value="5" />

And what I need to do, is: uncheck specified radio value something
like:

document.forms.editRegistration.options[23].checked = false;

This isn't working, so it's not the correct way to do it, can any one
help me on this one?

Thanks in advance
 
E

Evertjan.

João Morais wrote on 01 okt 2007 in comp.lang.javascript:
I there guys,

I have something like this:

<input type="radio" name="options[10]" value="1" />
<input type="radio" name="options[10]" value="2" />
<input type="radio" name="options[10]" value="3" />

<input type="radio" name="options[23]" value="9" />
<input type="radio" name="options[23]" value="5" />

Please do not use /> , where just > is html.

options[23] suggests an array, but an input name cannot be an array.

so it must be just a string.
And what I need to do, is: uncheck specified radio value something
like:

document.forms.editRegistration.options[23].checked = false;

See: here you try to use it as an array!
This isn't working, so it's not the correct way to do it, can any one
help me on this one?

try this and you will see what happens:

=================================
<script type='text/javascript'>
function clearMe(){
var rr = document.forms[0].elements['options[10]'];
alert(rr.length + ' (length of options[10])');

var r = document.forms[0].elements['options[23]'];
alert(r.length + ' (length of options[23])');

alert(r[0].checked + ' (status of the 1th of options[23])');
r[0].checked = false; // uncheck !!!
alert(r[0].checked + ' (status of the 1th of options[23])');
alert(r[0].value + ' (value of the 1th of options[23])');
};
</script>

<form>
<input type="radio" name="options[10]" value="1" >
<input type="radio" name="options[10]" value="2" >
<input type="radio" name="options[10]" value="3" >
<input type="radio" name="options[23]" value="9" checked>
<input type="radio" name="options[23]" value="5" >
</form>

<button onclick='clearMe()'>
clear the first radiobuton of options[23] valued 5
</button>
=================================

advice, use:

name="options23"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top