SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to show selected radio option - not working!

    Arg. I've been looking at this for too long, and everything is fuzzy now.

    I have the following HTML and javascript code that doesn't work. Basically, when the submit button is clicked, I want whatever radio option is selected to be displayed in a popup.

    Instead, it pops up and says "undefined".

    Any ideas?
    Code:
    <HTML>
    <HEAD>
    </HEAD>
    <script language="JavaScript">
    <!--
    function showValue(){
    
    	alert(document.form1.the_name.value);
    }
    //-->
    </script>
    <BODY>
    <FORM NAME="form1" METHOD="post" onSubmit="showValue();"> 
    <INPUT TYPE="radio" NAME="the_name" VALUE="creditcard" CHECKED>Option 1<BR>
    <INPUT TYPE="radio" NAME="the_name" VALUE="online_check">Option 2<BR>
    <INPUT TYPE="submit" NAME="submit" VALUE="Show Selected Option">
    </FORM>
    </BODY>
    </HTML>
    Thanks for any help!
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do something along the lines of this

    PHP Code:
    <html>
    <
    head>
    <
    title></title>
    </
    head>

    <
    script language="Javascript">
    <!--

        function 
    showvalue(x)
        {
            
    x.value;
            
    open ('','','');
            
    a.document.write(x);
        }
    //-->
    </script>

    <body>

        <form    name="form1"        method="post"   onsubmit="showvalue();">

            <input type="radio"  name="transfer" value="credit"               onclick="showvalue(this)" checked>option 1<br>
            <input type="radio"  name="transfer" value="cheque"             onclick="showvalue(this)">option 2<br>
            <input type="submit" name="submit"   value="Show selected Option">

        </form>
    </body>
    </htmL> 

  3. #3
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work with the onSubmit:

    Code:
    <script language="javascript">
    function radioCheck() {
    var sVal;
    var i;
    
      for (i = 0; i < 2; i++) { 
        if (eval("document.forms[0].transfer[" + i + "].checked")) { 
          sVal = (eval("document.forms[0].transfer[" + i + "].value")); 
          alert(sVal);
          break; 
        }  //end if
      }  //end loop
      document.form1.submit();
    
    }
    </script>
    
    ...
    
    <body>
    
      <form  name="form1" method="post">
        <input type="radio"  name="transfer" value="credit" checked>option 1<br>
        <input type="radio" name="transfer" value="cheque" >option 2<br>
        <input type="button" name="submit" value="Show selected Option" onClick="radioCheck()">
    
        </form>
    </body>
    Last edited by makeda; Apr 16, 2002 at 05:33.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •