[Javascript] function detecting selected radio button option -- with one failure

Abraham Liu liuabe99 at hotmail.com
Tue Jan 29 13:54:56 CST 2002


Hi Bill,
I had the same problem you have now several months ago. one good heart 
person told me a way to work around it.
In your function, you create a counter to count the number of buttons you 
are going to generate. If counter = 1, create a "select" button which will 
work properly if only one existed. Otherwise create radio buttons.
If you can accept this solution, try it.
Abe Liu

>From: "Bill" <javascript at unlockedideas.com>
>Reply-To: javascript at LaTech.edu
>To: <javascript at LaTech.edu>
>Subject: [Javascript] function detecting selected radio button option -- 
>with one failure
>Date: Tue, 29 Jan 2002 11:41:31 -0600
>
>Here's one:
>
>I've got a function that I use to identify which radio button a user 
>selects. It works great if you have more than one radio button in the 
>group.
>
>My problem is that my radio buttons are dynamically generated, and 
>sometimes only one radio button is in the group.
>
>Can someone see what the problem is which my function, get_radio_value()? 
>To make the snippet below work correctly, uncomment the second radio 
>button.
>
>Best,
>
>Bill
>
><script language=javascript>
><!--
>function get_radio_value (radio_array)
>{
>  var i;
>  for (i = 0; i < radio_array . length; ++ i)
>   if (radio_array [i] . checked)
>    return radio_array [i] . value;
>  return null;
>}
>
>function run_choice() {
>  document.write( get_radio_value(sel.radiobutton) )
>  document.write("<p><input type=button value=Back")
>  document.write(" onClick='history.back()'>")
>}
>
>//-->
></script>
><form name=sel method=post>
>       <input type="radio" name="radiobutton" value="01003">01003
>       <!-- input type="radio" name="radiobutton" value="01004">01004 -->
>
>       <p><input type=button name=ok value=OK onClick='run_choice()'>
></form>
>




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




More information about the Javascript mailing list