ticked check box

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
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

ticked check box

Post by Jim_Bo »

Hi,

How do you make a checkbox show as checked as you would to show the selected value in a list menu:

A list menu:

Code: Select all

<option <?php echo $method=='Drive' ? 'selected' : ''?>>Drive</option>

Code: Select all

&lt;input type=&quote;checkbox&quote; name=&quote;c3&quote; value=&quote;car&quote; class=&quote;input-box&quote;&gt;
How can I display the above as checked in the same manner as the list menu.

Thanks
wyred
Forum Commoner
Posts: 86
Joined: Mon Dec 20, 2004 1:59 am
Location: Singapore

Post by wyred »

The word to use is 'checked'.

Code: Select all

<input type=&quote;checkbox&quote; name=&quote;somebox&quote; checked>
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

I have error checking on the form, I only want it show checked if it was allready checked before it was submitted, else leave it unchecked. Same as the list/menu option above.


Thanks
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Code: Select all

<input type="checkbox" name="c3" value="car" class="input-box" <?php echo isset($c3) ? 'checked="checked"' : ''; ?> />
should be checked='checked' or selected='selected' unless you're using the old outdated crap. ;)
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Thanks for that, works fine.
Post Reply