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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button OnClick Event

Status
Not open for further replies.

Kendel

Programmer
Apr 24, 2002
1,512
US
Hi,

I want to display a value in a textbox based on the value of a selected rdo button. This is what I have so far but it didn't work.

<td><input type=&quot;radio&quot; name=&quot;rdoDate&quot; value=&quot;somevalue&quot; onclick=&quot;call WhichOne>somevalue</td>
<td><input type=&quot;radio&quot; name=&quot;rdoDate&quot; value=&quot;nextvalue&quot; onclick=&quot;call WhichOne>nextvalue</td>

<td><input type=&quot;text&quot; name=&quot;txtDate&quot; value=&quot;<%=Request(&quot;rdoDate&quot;)></td>

<script language=&quot;VBScript&quot;>
Function WhichOne
form1.txtDate.value = from1.rdoDate.value
End Function
</script>

When a button is clicked, I got &quot;error on page&quot;

Can someone plase show me what I'm doing wrong here.

Thanks
 
You'll have to do something along these lines (see below). Option buttons don't have a Value property that you can tap into. You could though test for the Checked property (whether it's true false) but to do that you'll have to give them different names or use their indexes ie.
The first radio button in the form would be rdoDate(0), the second rdoDate(1) etc. So, you could name them both rdoDate and in your sub say:
If form1.rdoDate(0).checked = true then
form1.txtDate.value=&quot;whatever&quot;
end if

<html><head></head><body>
<form name=&quot;form1&quot; >
<table border=&quot;1&quot;>
<tr>
<td><input type=&quot;radio&quot; name=&quot;rdoDate&quot; value=&quot;somevalue&quot; onclick=&quot;WhichOne('1')&quot;>somevalue</td>
</tr>
<tr>
<td><input type=&quot;radio&quot; name=&quot;rdoDate&quot; value=&quot;nextvalue&quot; onclick=&quot;WhichOne('2')&quot;>nextvalue</td>
</tr>
<tr>
<td><input type=&quot;text&quot; name=&quot;txtDate&quot;></td>
</tr>
</table>
</form>
</body>
</html>
<script language=&quot;VBScript&quot;>
Sub WhichOne(i)
IF i = 1 then
form1.txtDate.value= &quot;somevalue&quot;
ELSE
form1.txtDate.value= &quot;nextvalue&quot;
End if
End Sub
</script>
 
Actually onclick will always make the current radio button 'checked', so setting the value into the text box will be fine.

Here it is in JavaScript, you can port it into client side vbscript if you like .. [3eyes]

Code:
<td><input type=&quot;radio&quot; name=&quot;rdoDate&quot; value=&quot;somevalue&quot; onclick=&quot;WhichOne(this)&quot;>somevalue</td>
<td><input type=&quot;radio&quot; name=&quot;rdoDate&quot; value=&quot;nextvalue&quot; onclick=&quot;WhichOne(this)&quot;>nextvalue</td>

<td><input type=&quot;text&quot; name=&quot;txtDate&quot; value=&quot;<%=Request(&quot;rdoDate&quot;)%>&quot;></td>

<script language=&quot;JavaScript&quot;>
function WhichOne (radioBtn) {
   form1.txtDate.value = radioBtn.value;
}
</script>

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top