delickate Posted June 24, 2008 Share Posted June 24, 2008 hi guys, i need check box validation. if i didn't check it then it must alert error "please agree term and condition". if it checked it it should not return and thing. i m using following code function checkBoxes(fld) { if (!fld.checked) { error ="Please agreed to the Terms and Conditions!"; return error; } return true; } it works well. when i didnt check it return error.but if i check it. it again lert "true". i need to skip return true.if i check it it didnt show alert. any one know how to? Link to comment https://forums.phpfreaks.com/topic/111629-checkbox-validation-help-plz/ Share on other sites More sharing options...
phpSensei Posted June 24, 2008 Share Posted June 24, 2008 You dont need a function for such a small thing Try: <?php if(isset($_POST['checkbox'])){ checkbox is checked } else { its not checked } ?> or: function is_checked($checkbox){ $checkbox = (isset($checkbox)) ? true : false; if($checkbox){ return true; } else { return false; } // OR return $checkbox } Link to comment https://forums.phpfreaks.com/topic/111629-checkbox-validation-help-plz/#findComment-573019 Share on other sites More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 Yeah, I usually just do something like: <?php if (isset($_POST['checkbox'])) { $checked = 'checked="checked"'; } else { $checked = ''; } echo '<input type="checkbox" name="whatever" value="val" '.$checked.' />'; ?> Link to comment https://forums.phpfreaks.com/topic/111629-checkbox-validation-help-plz/#findComment-573025 Share on other sites More sharing options...
Psycho Posted June 24, 2008 Share Posted June 24, 2008 @delickate, You posted JavaScript not PHP. Which are you wanting: a PHP validation or a JavaScript validation? There is no "checked" property on a POSTed value in PHP. Link to comment https://forums.phpfreaks.com/topic/111629-checkbox-validation-help-plz/#findComment-573027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.