Jump to content

checkbox validation help plz


delickate

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.