...

View Full Version : radio buttons



Bob42
01-26-2008, 04:13 AM
I am coding a script that takes info from a database and displays it on a page. Right now there is a field in my database called "status" and I want the value in that field to be displayed in the form of radio buttons.



<input type=\"radio\" name=\"status\" value=\"{$row['status']}\" checked=\"checked\" /> Administrator
&nbsp;&nbsp;<input type=\"radio\" name=\"status\" value=\"{$row['status']}\" checked=\"checked\" /> Manager
&nbsp;&nbsp;<input type=\"radio\" name=\"status\" value=\"{$row['status']}\" checked=\"checked\" /> Moderator


So if "Administrator" is placed in the "status" field, then the Administrator button would be selected.

Inigoesdr
01-26-2008, 05:07 AM
The value for radio buttons should be static, and you set the correct one to checked based on the current value in $row:

echo "<input type=\"radio\" name=\"status\" value=\"Administrator\" " . ($row['status'] == 'Administrator' ? ' checked="checked"' : '') . "/> Administrator&nbsp;&nbsp;
<input type=\"radio\" name=\"status\" value=\"Manager\" " . ($row['status'] == 'Manager' ? ' checked="checked"' : '') . "/> Manager&nbsp;&nbsp;
<input type=\"radio\" name=\"status\" value=\"Moderator\" " . ($row['status'] == 'Moderator' ? ' checked="checked"' : '') . "/> Moderator";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum