doc said:
Hi,
<SCRIPT LANGUAGE="JavaScript">
The language attribute is depreciated, type is required:
function check_selection(selection){
document.pr.n_o[selection][0].checked=true;
This seems to be trying to refer to a form with a name 'pr', an
element collection with a name 'n_o' and element index 'selection'
which itself is a collection... and that's where your trouble is.
If you want to use the syntax you have constructed, then:
document.pr.elements['n_o[' + selection + ']'].checked = true;
will do the trick. A more robust version is:
document.forms['pr'].elements['n_o[' + selection + ']'].checked=true;
I'd suggest not using square brackets this way, use some other
character such as '-', '.' or '_' to separate your pseudo-index from
the name.
"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")."
}
</SCRIPT>
<form name=pr action=test.php method=post>
While it is not mandatory to quote attributes, it is always a good
idea and (AFAIKR) all examples the W3C HTML spec use quotes:
<input type=radio name="n_o[2]" value="yes">yes
<select name="n_w[2]" onChange="check_selection(2)" >
When passing a digit that is to be used as a string, it may be better
to pass it as a string, although in this case it doesn't matter but
it may make it more obvious to someone else trying to maintain your
code:
.....
</select>
</form>
after changing select object i'm receiving error:
Error 'document.pr.n_o' is null or not an object.
Do you have any idea's how to fix it?
Working version:
<script type="text/javascript">
function check_selection(selection){
document.pr.elements['n_o[' + selection + ']'].checked = true;
}
</script>
<form name="pr" action="">
<input type=radio name="n_o[2]" value="yes">yes
<select name="n_w[2]" onChange="check_selection('2')">
<option>one</option>
<option>two</option>
</select>
<input type="reset">
</form>