Results 1 to 5 of 5

Thread: Capture radio button value

  1. #1
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Capture radio button value

    I have an HTML form with JavaScript validation.

    What I have been trying to solve is displaying the value of radio buttons when the form has been completed and sent (by email).

    function checkRIF(theForm)

    {



    var data = document.ChargeRequest;
    var userinfo = "";
    var sender = data.fullname.value;

    theForm.action += "?charge=" + data.fullname.value;

    userinfo += "\n\nPage Title: " + document.title + "\n\n";

    theForm.mailbody.value = userinfo + "PART A: " + "\n\n" + "text1: " + data.text1.value + "\n\n" + "radio button: " + data.radio.checked ";
    return true;
    }

    I get 'undefined' when the form is submitted. Can someone help me capture the value of the radio button?
    <body>
    <p>Yes
    <input type="radio" name="radio" id="radio1" value="Yes">
    No
    <input type="radio" name="radio" id="radio2" value="No">
    </p>
    </body>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

  3. #3
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can you think of another way then?

  4. #4
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Use PHP, e.g.:
    HTML Code:
    <form action="" method="post">
    <label for="radio1">Yes</label><input type="radio" name="radio" id="radio1" value="Yes">
    <label for="radio1">No</label><input type="radio" name="radio" id="radio2" value="No">
    <input type="submit" name="submit" value="Send">
    </form>
    PHP Code:
    <?php if (isset($_POST['submit'])) : ?>
    You said <?php $radio $_POST['radio']; echo $radio?> and that is awesome!
    <?php endif ?>
    Good luck!

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

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
  •