jeudi 25 août 2016

checkbox validation if the checkbox is displayed only

I have a form with a checkbox which is displayed in certain cases. I would like to check that the checkbox is checked only in case it's displayed, for other cases I would like the form to be submitted on click on the submit button. I wrote the following function, but it doesn't work:

function checkTheBox() {
window.onload = function() {
var visible = document.getElementById("checkbox").isDisplayed();
if(!visible)
    return true;
else if(visible){
    var checkbox = document.getElementById("checkbox");
    if(checkbox.checked)
        return true;   }
    else{
        alert('You must agree to the terms first.');
        return false;
    }
}; }

These are my html elements:

  <div class='input-block' id='div_checkbox' style='display: none;'> 
  <input type="checkbox" id="checkbox" name="checkbox" value="0">
  <b>I agree to all terms and conditions</b><br />
    </div>

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire