Jump to content

Radio Button Problem


creacon
 Share

Recommended Posts

My questionnaire form is mostly radio button groups (Yes/No), and when the submit button is pressed the answers must be saved to a MySQL table. I can't seem to figure out how to capture the answers into php to save them. Everything in the w3Schools references shows ONLY javascript, and ONLY shows how to set and clear them; nothing about how to find out which were checked by the user, nor how to get the information to the php script. Here's my php code:

   <?php	session_start();		if (isset($_POST['submit'])){		// Fetch a radio button to see what the response is.		$radiogp1 = $_POST["RadioGroup1"];	// This is the "Name" value for a radio button pair		echo "<br /> $radiogp1 <br />";		$radio1_1 = $_POST["RadioGroup1_1"];	// This is the "id" value of an individual radio button		echo "$radio1_1 <br />";		echo "HEY, We're Here";  // This should display no matter what, but it doesn't				echo '<META http-equiv="refresh" content="10;URL=WOTCPLogout.php">';//		header("Location: WOTCLogoff.php");}	else{		$arrappl = $_SESSION['sesarrappl'];		$applname = $arrappl[fullname].", DOB: ".$arrappl[dob];		}	?> 

And that's another thing; why is it so difficult to get php to display something on the page for debugging purposes? I have another page that echo's variables for debugging, and they display as they should, but this one doesn't. Instead, as soon as the submit button is pressed the form refreshes then after the 10 seconds goes away (at least that much works). This is so frustrating. I'm getting NOWHERE at a very high rate of speed.While waiting, I tried adding the following javascript (not that this will help me get the answers into php), and in the submit button I added: onClick="checkValue()"

  	function checkValue()	{		if (document.getElementById("RadioGroup1_1").checked==true)		{			alert("The No button was checked");		}		else		{			alert("It must've been the Yes button");		}	}

And it works IN REVERSE; when I check the Yes button I get the first alert, and when I check the No button I get the second one. Whaaaa?

Edited by creacon
Link to comment
Share on other sites

Thanks a bazillion, that link was a godsend! I put it's home page in my favorites.Also I found out why I wasn't seeing any displays. They were actually there, but it's extremely hard to read white on white. I accidentally highlighted the top of the page and Voila, there were the displays. Since this is a mockup page for testing purposes, I changed the bacground color, and now I can see my testing messages.It's really a shame that you can't diplay an alert box from php (or if you can, someone please tell me how).Anyway, thanks again for the help.
Link to comment
Share on other sites

You can echo javascript tags and drop whatever variables you want into the alert, if you really felt like going that far.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...