Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting different controls

Status
Not open for further replies.

Kirogl

Programmer
Mar 24, 2004
14
0
0
GB
Hi,
I want to use radio button to select a textbox, so that when a user click's on a link, depening on which button is currently selected, a value is posted to one of two text boxes.

however IE keeps throwing up an error on line 21/22 (the line of HTML that calls the JS function) What am I missing?

I've posted the code (or as much as is relevent) to explain whats going on (or not)

Code:
<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">


function setbox(myValue){
if (document.myForm.1[1].selected) {
document.box1.value = myValue
}
if (document.myForm.1[2].selected) {
document.box2.value = myValue
}
}

</SCRIPT>

</head>
<body>

<a href="#" onClick="setbox(14)">14</a><br />
<a href="#" onClick="setbox(16)">16</a><br />

<form name=myForm >
<table><tr><td>
<input type="radio" name="1" value="test1" ><br>
</td></tr><tr><td>
<input type="radio" name="1" value="test2" ><br>
</td></tr></table>
</form>

<form name=myForm2 >
<table><tr><td>
<INPUT TYPE="text" NAME="box1" VALUE="">
</td></tr><tr><td>
<INPUT TYPE="text" NAME="box2" VALUE="">
</td></tr></table>
</form>

</BODY>
</HTML>

-----
 
Start name attribute by no number, only underscore or alphabets.
 
Fixed it!
Thanks tsuji for the hint.
here's the final code (in case anyone else has similer problems)
Code:
<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">


function setbox(myValue){
if (document.myForm.but[0].checked) {
document.myForm2.boxone.value = myValue
}
if (document.myForm.but[1].checked) {
document.myForm2.boxtwo.value = myValue
}
}

</SCRIPT>

</head>
<body>

<a href="#" onClick="setbox(14)">14</a><br />
<a href="#" onClick="setbox(16)">16</a><br />

<form name=myForm >
<table><tr><td>
<input type="radio" name="but" value="test1" ><br>
</td></tr><tr><td>
<input type="radio" name="but" value="test2" ><br>
</td></tr></table>
</form>

<form name=myForm2 >
<table><tr><td>
<INPUT TYPE="text" NAME="boxone" VALUE="">
</td></tr><tr><td>
<INPUT TYPE="text" NAME="boxtwo" VALUE="">
</td></tr></table>
</form>

</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top