Jump to content

PHP conditional setting of radio button default


vozzek

Recommended Posts

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.

 

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.