Form Validation (Radio Buttons...)

Hi Guys,

I have created a very simple form with a text box and radio buttons. I am using javascript to echo my php in a div but it won’t allow me to see which radio button was selected! Nightmare… :frowning:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>


<form id="testForm" method="post" >

<input type="text" name="info" >info<br>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female

<input type="submit" value="Submit">

<div id="response">
         	<div class="clearer"></div><!--clearer-->

 <script src="" type="text/javascript"></script>
<script type="text/javascript" src="js/testForm.js"></script>

testForm.js file

		var sex_Js = $("#sex").val();
		var info_Js = $("#info").val();
	return false;

    $nameField_PHP = $_POST['sex'];

    $info_PHP = $_POST['info'];

        echo $info_PHP;
        echo "<br />" . $nameField_PHP;


Why isn’t the javascript sending the radio buttons value through to the PHP?

Many thanks.

JavaScript can see all the radio buttons whether they are selected or not - you need to loop through them all to find the selected one if you want to reference that in JavaScript. Only the selected one gets passed to PHP so in PHP the radio button group is no different from an input field where one of the values associated with the buttons gets entered.