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? Quote Link to comment 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 } Quote Link to comment 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.' />'; ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.