Fweddie
asked on
On change event for VBScript Radio button
Here's my code:
<SCRIPT LANGUAGE="VBScript">
<!--
private sub optRate_onChange()
msgbox "Hello"
End sub
'More code here at the bottom
</SCRIPT>
and here's part of the HTML code
<TR class=clsoddrow>
<TD>
<INPUT type="radio" name="optRate" value="1" >Branch-Quoted
</TD>
<TD>
<INPUT type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
</TD>
<TD colspan=2> </TD>
</TR>
<TR class=clsevenrow>
<TD><INPUT type="radio" name="optRate" value="2" >Treasury-Quoted
</TD>
<TD>
<INPUT type=TEXT name="txtTreasuryRate" size=14 maxlength=14 value="0">
</TD>
<TD> Reference Number </TD>
<TD>
<INPUT type="text" name="txtTreasuryRefNo" maxlength="20" size="22" value="" >
</TD>
</TR>
what i want to happen is that everytime someone click on the radio button, it would go in my function (I don't know if i should use onchange or onclick) Also, how would i know which radio button is currently selected?
<SCRIPT LANGUAGE="VBScript">
<!--
private sub optRate_onChange()
msgbox "Hello"
End sub
'More code here at the bottom
</SCRIPT>
and here's part of the HTML code
<TR class=clsoddrow>
<TD>
<INPUT type="radio" name="optRate" value="1" >Branch-Quoted
</TD>
<TD>
<INPUT type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
</TD>
<TD colspan=2> </TD>
</TR>
<TR class=clsevenrow>
<TD><INPUT type="radio" name="optRate" value="2" >Treasury-Quoted
</TD>
<TD>
<INPUT type=TEXT name="txtTreasuryRate" size=14 maxlength=14 value="0">
</TD>
<TD> Reference Number </TD>
<TD>
<INPUT type="text" name="txtTreasuryRefNo" maxlength="20" size="22" value="" >
</TD>
</TR>
what i want to happen is that everytime someone click on the radio button, it would go in my function (I don't know if i should use onchange or onclick) Also, how would i know which radio button is currently selected?
btw, you can call that as
<INPUT type="radio" name="optRate" value="1" onclick="radioclick()">
<INPUT type="radio" name="optRate" value="2" onclick="radioclick()">
or do it directly (without using the function),
<INPUT type="radio" name="optRate" value="1" onclick="alert(this.value) ;//execute function here">
<INPUT type="radio" name="optRate" value="2" onclick="alert(this.value) ;">
<INPUT type="radio" name="optRate" value="1" onclick="radioclick()">
<INPUT type="radio" name="optRate" value="2" onclick="radioclick()">
or do it directly (without using the function),
<INPUT type="radio" name="optRate" value="1" onclick="alert(this.value)
<INPUT type="radio" name="optRate" value="2" onclick="alert(this.value)
why use vbscript? it's not supported on NS browsers.
function radioclick(){
var obj = document.forms[0];
for(var i=0;i<obj.length;i++){
if((obj.elements[i].type== "radio") && (obj.elements[i].checked)) {
alert(obj.elements[i].valu e);
//execute your function
}
}
}
function radioclick(){
var obj = document.forms[0];
for(var i=0;i<obj.length;i++){
if((obj.elements[i].type==
alert(obj.elements[i].valu
//execute your function
}
}
}
ooppss, ignore it. it's just the same with the first post.
ASKER
I'm using RDS and I have to use VBScript (unless there's a way to call a VBScript function from Javascript). Javascript would have been easier on this :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<html>
<head>
<script language="vbscript">
function radioclick()
dim obj, i
set obj = document.forms(0)
for i=0 to obj.length-1
if (obj.elements(i).type="rad io") and (obj.elements(i).checked) then
msgbox "the value of the selected radio button is " + obj.elements(i).value
'execute function here ....
exit for
end if
next
end function
</script>
</head>
<body>
<form>
<input type="radio" name="optRate" value="1" onclick="radioclick">Branc h-Quoted
<input type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
<input type="radio" name="optRate" value="2" onclick="radioclick">Treas ury-Quoted
<input type="text" name="txtTreasuryRate" size=14 maxlength=14 value="0">
<input type="text" name="txtTreasuryRefNo" maxlength="20" size="22" value="" >
</form>
</body>
</html>
<head>
<script language="vbscript">
function radioclick()
dim obj, i
set obj = document.forms(0)
for i=0 to obj.length-1
if (obj.elements(i).type="rad
msgbox "the value of the selected radio button is " + obj.elements(i).value
'execute function here ....
exit for
end if
next
end function
</script>
</head>
<body>
<form>
<input type="radio" name="optRate" value="1" onclick="radioclick">Branc
<input type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
<input type="radio" name="optRate" value="2" onclick="radioclick">Treas
<input type="text" name="txtTreasuryRate" size=14 maxlength=14 value="0">
<input type="text" name="txtTreasuryRefNo" maxlength="20" size="22" value="" >
</form>
</body>
</html>
ASKER
Here's my code now:
<SCRIPT LANGUAGE="VBScript">
<!--
Private Function Radio_click()
msgbox "HELLO"
end Function
'-- more scripts here
</SCRIPT>
<TR class=clsevenrow>
<TD><input type="radio" name="optRate" value="1" onclick="Radio_click()">Br anch-Quote d
</TD>
<TD>
<INPUT type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
</TD>
<TD colspan=2> </TD>
</TR>
<TR class=clsoddrow>
<TD><input type="radio" name="optRate" value="2" onclick="Radio_click()">Tr easury-Quo ted
</TD>
<TD>
<INPUT type=TEXT name="txtTreasuryRate" size=14 maxlength=14 value="196">
</TD>
<TD> Reference Number </TD>
<TD>
<INPUT type="text" name="txtTreasuryRefNo" maxlength="20" size="22" value="" >
</TD>
</TR>
i now get an "Object Expected" error when i click on the radio button...
<SCRIPT LANGUAGE="VBScript">
<!--
Private Function Radio_click()
msgbox "HELLO"
end Function
'-- more scripts here
</SCRIPT>
<TR class=clsevenrow>
<TD><input type="radio" name="optRate" value="1" onclick="Radio_click()">Br
</TD>
<TD>
<INPUT type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
</TD>
<TD colspan=2> </TD>
</TR>
<TR class=clsoddrow>
<TD><input type="radio" name="optRate" value="2" onclick="Radio_click()">Tr
</TD>
<TD>
<INPUT type=TEXT name="txtTreasuryRate" size=14 maxlength=14 value="196">
</TD>
<TD> Reference Number </TD>
<TD>
<INPUT type="text" name="txtTreasuryRefNo" maxlength="20" size="22" value="" >
</TD>
</TR>
i now get an "Object Expected" error when i click on the radio button...
What browser you use ?
BEcause i don't have this problem.
BEcause i don't have this problem.
ASKER
please note that i have a javascript part before the vbscript part. would this be a problem? (conflicting script languages perhaps?)
remove private from the function
Function Radio_click()
msgbox "HELLO"
end Function
btw, have you tried my example?
Function Radio_click()
msgbox "HELLO"
end Function
btw, have you tried my example?
ASKER
ok, got it to work. I just added the VBScript part on top of the java script part
so instead of
<script language=javascript>
//scripts here
</Script>
<script language=vbscript>
'--scripts here
</Script>
i did
<script language=vbscript>
'--scripts here
</Script>
<script language=javascript>
//scripts here
</Script>
so instead of
<script language=javascript>
//scripts here
</Script>
<script language=vbscript>
'--scripts here
</Script>
i did
<script language=vbscript>
'--scripts here
</Script>
<script language=javascript>
//scripts here
</Script>
ASKER
i've modified third's code to reproduce the error
<html>
<head>
<script language="vbscript">
function radioclick()
dim obj, i
set obj = document.forms(0)
for i=0 to obj.length-1
if (obj.elements(i).type="rad io") and (obj.elements(i).checked)
then
msgbox "the value of the selected radio button is " +
obj.elements(i).value
'execute function here ....
exit for
end if
next
end function
</script>
<script language="javascript">
function Window_OnLoad()
{
alert("Hello");
}
</script>
</head>
<body onload="Window_OnLoad();">
<form>
<input type="radio" name="optRate" value="1"
onclick="radioclick">Branc h-Quoted
<input type="text" name="txtBranchRate" maxlength="20" size="22"
value="" >
<input type="radio" name="optRate" value="2"
onclick="radioclick">Treas ury-Quoted
<input type="text" name="txtTreasuryRate" size=14 maxlength=14
value="0">
<input type="text" name="txtTreasuryRefNo" maxlength="20" size="22"
value="" >
</form>
</body>
</html>
<html>
<head>
<script language="vbscript">
function radioclick()
dim obj, i
set obj = document.forms(0)
for i=0 to obj.length-1
if (obj.elements(i).type="rad
then
msgbox "the value of the selected radio button is " +
obj.elements(i).value
'execute function here ....
exit for
end if
next
end function
</script>
<script language="javascript">
function Window_OnLoad()
{
alert("Hello");
}
</script>
</head>
<body onload="Window_OnLoad();">
<form>
<input type="radio" name="optRate" value="1"
onclick="radioclick">Branc
<input type="text" name="txtBranchRate" maxlength="20" size="22"
value="" >
<input type="radio" name="optRate" value="2"
onclick="radioclick">Treas
<input type="text" name="txtTreasuryRate" size=14 maxlength=14
value="0">
<input type="text" name="txtTreasuryRefNo" maxlength="20" size="22"
value="" >
</form>
</body>
</html>
"i've modified third's code to reproduce the error"
??
??
ASKER
found the error.
it seems that i have to do the vbscript part first before the java script part. also, i had to remove the semi colon on the onload function when calling it
it seems that i have to do the vbscript part first before the java script part. also, i had to remove the semi colon on the onload function when calling it
function radioclick(){
var obj = document.forms[0];
for(var i=0;i<obj.length;i++){
if((obj.elements[i].type==
alert(obj.elements[i].valu
//execute your function
}
}
}