[Javascript] radio button problem

Alan Easton alan.easton at unn.ac.uk
Wed Mar 19 08:04:16 CST 2003


Thanks David

That is what I was thinking had to be done.

Works just like I want it.

Many Thanks,

Alan...

-----Original Message-----
From: David T. Lovering [mailto:dlovering at gazos.com]
Sent: 19 March 2003 13:56
To: javascript at LaTech.edu
Subject: Re: [Javascript] radio button problem



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



More information about the Javascript mailing list