Jump to content

values into radio/check and drop down menus


mishuk

Recommended Posts

Hi.  I am attempting to create an update form where the current fields in the table are populated into input boxes and then can be altered where necessary.

 

I was wondering if it is possible to pre check radio buttons, check boxes and pre populate drop down menus based on the results currently in the table.

 

eg. if the gender of a person is male then the radio button will be pre checked as male.

 

How would this be done.?

Cheers for the help.

Carrying on from this.  can i dynamically place a "selected" option in this drop down menu.

something like

echo '<option value="' . $row['ethnicity_id'] . '" if ($ethnicity=$row['ethnicity_id'] echo "selected">' . $row['ethnicity'] . '</option>';

 

What would be the correct syntax?

 

$res=mysql_query("select ethnic_id, ethnicity from tbl_ethnicity");

if(mysql_num_rows($res)==0) {
	echo "No Data";
} else {
echo '<select name="ethnicity">';
echo '<option value = "-1">Select:</option>';
while($row=mysql_fetch_assoc($res)) {
      echo '<option value="' . $row['ethnicity_id'] . '">' . $row['ethnicity'] . '</option>';
}
       echo '</select>';
};

yeh sorry that was me being careless.  Already tried that and get the error

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in ... on line 275

 

here is the full line

 

echo '<option value="' . $row['ethnicity_id'] . '" if ($ethnicity == $row['ethnicity_id']) echo "selected">' . $row['ethnicity'] . '</option>';

Still doesnt wor.  Here is a bigger chunk of the script.

At the beginning of the while $ethnicity is populated with the result from the student query

eg $ethnicity = 1 and i want to then dynamically generate the below drop down menu with the ethnicity corresponding to the $ethnicity selected

 

$res=mysql_query("select * from tbl_student where stud_id = $student");

while($row = mysql_fetch_array($res))
     {
     $ethnicity = $row['ethnic_id'];
  	?>
<FORM method="post" action="admin.php?do=editstu">
<TABLE BORDER="0" ALIGN="center">
<TR>
    <TD>Ethnicity:</TD>
    <TD>
<?	$res=mysql_query("select ethnic_id, ethnicity from tbl_ethnicity");
if(mysql_num_rows($res)==0) {
	echo "No Data";
} else {
	echo '<select name="ethnicity">';
	echo '<option value = "-1">Select:</option>';
	while($row=mysql_fetch_assoc($res)) {
	echo '<option value="' . $row['ethnicity_id'] . '">' . $row['ethnicity'] . '</option>';
	}
	echo '</select>';
};
?>
</TD>
</TR>
<TR>
<TD><input name="submit" type="submit" value="Update Student"></TD>
<TD><input name="reset" type="reset" value="Reset"></TD>
</TR>
</TABLE>
</FORM>

 

Thanks

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.