checkbox in form field problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steve_linn
Forum Newbie
Posts: 20
Joined: Thu Jul 10, 2008 1:10 pm

checkbox in form field problem

Post by steve_linn »

In an update form, how do I create a checkbox field?

here is an example of my code:

Code: Select all

 
 
<tr><td><h3>Admin Pref</h3></td><td><input type="text" name="adminpref" value="' .$row[adminpref].'"></td></tr>
    
<tr><td><h3>Video</h3></td><td><input type="checkbox" name="video" value="<?php if ('.$row[video].'=="1") 
    {echo "checked"};?>"</td></tr>
I cannot get the checkbox to be checked when the database value is set to 1....
thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: checkbox in form field problem

Post by John Cartwright »

The value attribute has nothing to do whether the checkbox is checked or not. It is it's own attribute.

A checked checkbox would look like

Code: Select all

<input type="checkbox" checked="checked" />
Post Reply