vozzek Posted October 9, 2007 Share Posted October 9, 2007 Hi everyone, I'm working on an edit inventory form, and I'm pulling a field from my database that's going to be a 'Y' or 'N'. Based upon this, I want to default the 'customizable' radio button to either checked="Y" or checked="N". <tr valign="baseline"> <td align="right" valign="top" nowrap="nowrap">Customizable:</td> <td valign="baseline"><table> <tr> <td><input onclick="document.form1.character_limit.disabled = false" type="radio" name="customizable" value="Y"/> Yes</td> <?php if ($row_rs_edit_inventory['customizable']=='Y') { ?> <script> document.form1.customizable.checked='Y' </script> <?php }else{ ?> <script> document.form1.customizable.checked='N' </script> <?php } ?> </tr> <tr> <td><input onclick="document.form1.character_limit.disabled = true" type="radio" name="customizable" value="N"/> No</td> </tr> </table></td> </tr> Not sure why, but this isn't working. No matter what's in the database, the radio button is defaulting to 'Y'. Does it matter whether I place this code in the 'Y' input portion of the radio button or the 'N'? Should I put it before both inputs? Not sure. I'm also pretty sure I'm going about this the hard way. Any ideas? Thanks in advance. EDIT: Came up with something else (much simpler), but it doesn't work either: <script> if <?php echo $row_rs_edit_inventory['customizable']; ?>=='Y' document.form1.customizable.checked='Y' else document.form1.customizable.checked='N' </script> Sorry in advance is this is all newbie stuff, I'm still learning. Quote Link to comment https://forums.phpfreaks.com/topic/72494-php-conditional-setting-of-radio-button-default/ Share on other sites More sharing options...
trq Posted October 9, 2007 Share Posted October 9, 2007 One simple method.... <?php echo '<input type="radio" name="customizable" value="N"' . (($row_rs_edit_inventory['customizable']=='Y') ? ' checked="checked"' : ''); ?>>'; not sure its what your after, but it might help. Quote Link to comment https://forums.phpfreaks.com/topic/72494-php-conditional-setting-of-radio-button-default/#findComment-365556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.