Copy codeThe Code is as follows: <Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> control over elements with the same name </title>
<Script language = "javascript">
Function setFlag (aObj)
{
If (! AObj)
Return false;
If (aObj. form. box. length> 1) // more than one
{
For (I = 0; I <aObj. form. box. length; I ++)
If (aObj. form. box [I] = aObj)
If (aObj. form. box [I]. checked)
AObj.form.txt [I]. value = "OK ";
Else
AObj.form.txt [I]. value = "";
}
Else
{
AObj.form.txt. value = "oks" // if there is only one row (no duplicate names)
}
}
</Script>
</Head>
<Body>
<Form name = "form1" method = "post" action = "">
1 <input name = "box" type = "checkbox" id = "box" value = "" onClick = "javascript: setFlag (this ); "/> <input name =" txt "type =" text "id =" txt "/> <br>
2 <input name = "box" type = "checkbox" id = "box" value = "" onClick = "javascript: setFlag (this ); "/> <input name =" txt "type =" text "id =" txt "/> <br>
3 <input name = "box" type = "checkbox" id = "box" value = "" onClick = "javascript: setFlag (this ); "/> <input name =" txt "type =" text "id =" txt "/>
</Form>
</Body>
</Html>