PDA

View Full Version : Capture radio button value



Macca
03-10-2009, 12:13 PM
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>

Nile
03-10-2009, 12:15 PM
I dont think so. (http://www.dynamicdrive.com/forums/showthread.php?t=21964)

Macca
03-10-2009, 01:23 PM
Can you think of another way then?

Snookerman
03-10-2009, 04:18 PM
Use PHP, e.g.:

<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 if (isset($_POST['submit'])) : ?>
You said <?php $radio = $_POST['radio']; echo $radio; ?> and that is awesome!
<?php endif ?>

Good luck!

Nile
03-10-2009, 10:54 PM
Check out the mail() function in php:
http://us.php.net/function.mail
http://www.w3schools.com/PHP/func_mail_mail.asp