简体   繁体   中英

Yes No check box

I'm new at php the form I'm creating has a Yes No checkbox my form works fine except if you check the Yes box and then check the No box they both stay highlighted. How can I make it so if the Yes box is checked and they check the No box the Yes box is unchecked. If you need my code let me know.

I've tried some of the code for checkbox but being new to php some of it doesn't make any sense.

You probably want to use radio button instead of checkbox. Radio button will automatically deselect when you choose the other option.

Example:

Gender:
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="other") echo "checked";?>
value="other">Other

This will render like: RadioButtonPng

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM