[Javascript] radio button problem

David T. Lovering dlovering at gazos.com
Wed Mar 19 07:56:08 CST 2003


Dear Alan:

  How about this --

  <html>
    <head>
      <title>myRadioButtons</title>
      <script language='JavaScript'>
      <!--
        function do_buttons(myValue) {
          if (!myValue) { return -1; }
          if (myValue == '') { return -1; }
          document.myForm.myValue.value = myValue;
          return true;
        }
      // -->
      </script>
    </head>
    <body>
      <form name='myForm'>
        <table name='myTable' id='myTable' align='center' cellpadding=3 cellspacing=0>
          <tr>
            <td></td>
            <td align='left' valign='middle'>
              <input type='radio' name='radiobutton' onClick='do_buttons(this.value)' value='Abraham Lincoln'>Abe
              <input type='radio' name='radiobutton' onClick='do_buttons(this.value)' value='Dwight Eisenhower'>Ike
            </td>
          </tr>
          <tr>
            <td align='right' valign='middle'>Your Selected Value</td>
            <td align='left' valign='middle'><input type='text' readonly name='myValue' size=30 value=''></td>
          </tr>
        </table>
      </form>
    </body>
  </html>

  When you click on a radio button (both are initially clear), the onClick event handler drops you into do_buttons with the value assigned to the button you just clicked.  Note that the value need not correspond to the visible label -- I did this just to
show that it was possible.  The handler then writes this value back out to the text field so you can see the results of your selection, and any other process (PHP, JavaScript, Java, ASP, whatever) should be able to read this like any other variable field.
 Since we don't want the user to type in arbitrary crap into this field which may be at odds with the value of whatever radio button is hightlighted, I've made the box a read-only.

  -- Dave Lovering

Alan Easton wrote:
> 
> Hi All,
> 
> My problem is this. I have 2 radio buttons on my ASP page, both have
> different values. I want the user to be able to select the appropriate radio
> button, and as they select it, I need a variable on the page to change to
> that value of the radio button that they have just selected.
> 
> The variable is then used further on in the application.
> 
> What is the best way to do this.
> 
> Any help is as always appreciated.
> 
> Many Thanks,
> 
> Alan...
> 
>   ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> 
>    Part 1.2    Type: application/ms-tnef (application/ms-tnef)
>            Encoding: base64
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dlovering.vcf
Type: text/x-vcard
Size: 304 bytes
Desc: Card for David T. Lovering
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030319/d3c47d9d/attachment.vcf>


More information about the Javascript mailing list