Solved

On change event for VBScript Radio button

Posted on 2002-04-09
15
1,030 Views
Last Modified: 2012-05-04
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> &nbsp; </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?
0
Comment
Question by:Fweddie
  • 7
  • 6
  • 2
15 Comments
 
LVL 30

Expert Comment

by:third
ID: 6930689
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].value);
      //execute your function
    }
  }
}
0
 
LVL 30

Expert Comment

by:third
ID: 6930714
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);">
0
 
LVL 30

Expert Comment

by:third
ID: 6930716
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].value);
      //execute your function
    }
  }
}
0
 
LVL 30

Expert Comment

by:third
ID: 6930718
ooppss, ignore it. it's just the same with the first post.
0
 

Author Comment

by:Fweddie
ID: 6930868
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 :(
0
 
LVL 14

Accepted Solution

by:
avner earned 50 total points
ID: 6930896
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Blank:Document </TITLE>
<META NAME="Author" CONTENT="(C)Avner Cohen">
<SCRIPT LANGUAGE="VBSCRIPT">

Function aa_onclick()
msgBox ("something")
End Function

</SCRIPT>
</HEAD>

<BODY>
<input type="radio" onclick="aa_onclick" >
</BODY>
</HTML>
0
 
LVL 30

Expert Comment

by:third
ID: 6932743
<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="radio") 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">Branch-Quoted
  <input type="text"  name="txtBranchRate" maxlength="20" size="22" value="" >
  <input type="radio" name="optRate" value="2" onclick="radioclick">Treasury-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>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Fweddie
ID: 6933128
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()">Branch-Quoted              
          </TD>
          <TD>
               <INPUT type="text" name="txtBranchRate" maxlength="20" size="22" value="" >
          </TD>
          <TD colspan=2> &nbsp; </TD>
     </TR>
     <TR class=clsoddrow>
          <TD><input type="radio" name="optRate" value="2" onclick="Radio_click()">Treasury-Quoted          
          </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...
0
 
LVL 14

Expert Comment

by:avner
ID: 6933130
What browser you use ?

BEcause i don't have this problem.
0
 

Author Comment

by:Fweddie
ID: 6933134
please note that i have a javascript part before the vbscript part. would this be a problem? (conflicting script languages perhaps?)
0
 
LVL 30

Expert Comment

by:third
ID: 6933141
remove private from the function

Function Radio_click()

msgbox "HELLO"

end Function


btw, have you tried my example?
0
 

Author Comment

by:Fweddie
ID: 6933143
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>

0
 

Author Comment

by:Fweddie
ID: 6933158
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="radio") 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">Branch-Quoted
 <input type="text"  name="txtBranchRate" maxlength="20" size="22"

value="" >
 <input type="radio" name="optRate" value="2"

onclick="radioclick">Treasury-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>
0
 
LVL 30

Expert Comment

by:third
ID: 6933177
"i've modified third's code to reproduce the error"

??
0
 

Author Comment

by:Fweddie
ID: 6933624
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript waiting 14 67
Disabled form text field 2 22
ngStyle with an input variable doesn't work 14 30
Polygon I google maps 1 14
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now