0

hey all,

I'm having some troubles with radio buttons. I'm trying to create them dynamically (which i can do without any problems) but now i'm not sure how to get the information of which button was selected. Can anyone help me? Thanks in advance:)

this is my code:

<html>
<head>
<?PHP

if (isset($_POST['Submit1'])) 
{
	for($l = 1; $l<$i;$l++)
	{
		$selected_radio = $_POST['RadioGroup1'];
		print $selected_radio;
		if ($selected_radio = $i) 
		{
			print $i;
		}
	}
}
else
{
	echo "hey";
}


?>
</head>
<body>
<Form name ="form1" Method ="Post" ACTION ="teste.php">
<?php
$mysql_host = "localhost";
$mysql_database = "gps";
$mysql_user = "root";
$mysql_passwd = "";

$conn = mysql_connect($mysql_host,$mysql_user,$mysql_passwd);

if(!$conn){
	die("Erro de ligação!");
	exit;	
}

$resultado = mysql_select_db($mysql_database,$conn);

	
if(!$resultado){
	die("Erro a obter dados!");
	exit;	
}
$result = mysql_query("SELECT * FROM lugares");
$i=1;
while($row = mysql_fetch_array($result))
{
  echo "<input type=\"radio\" name=\"RadioGroup1\" value=".$i." />".$i."<br />";	
  echo $row['Id_lugar'] . "<br /> " . $row['Ocupado'] . " <br />" . $row['Tipo'];
  echo "<br />";
  $i= $i+1;
}
for($l = 1; $l<$i;$l++)
{
		print $l;
}
?>
<P>
<Input type = "Submit" Name = "Submit1" Value = "Select a Radio Button">
</FORM>

</body>
</html>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sourcebits
0

If you will add a javascript function sel(val){} and the radio tag looks like this '<input type="radio" onchange="sel('.$i.')" name="RadioGroup1" value='.$i.' />'.$i.'<br />';
This will help in selecting the radio button. You have to choose between onclick or onchange event, it depends on what you need.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.