p singh
p singh

Reputation: 21

Trouble with executing code if checkbox is unchecked

I need to validate values of a form only if checkbox is unchecked. If it is checked, I will use values added previously. Now the thing is this or any of these code are not working. As I need to validate these values before I redirecting values to another form.

var ui=document.getElementById('same_info').value;
    ui.OnChange = valid;
       function valid()
         {var frmvalidator  = new Validator("myform");
        frmvalidator.addValidation("shipping_first_name","alpha_s","please enter your First Name or full name");
frmvalidator.addValidation("shipping_first_name","req","Please enter your First Name");

}

2.

 if(!document.myform.same_info.checked)

{ alert('infobox  is not checked'); }

I am using Javascript to validate form. Script is fine as it is working perfectly with form elements , whose values are not depending on checking/unchecking of checkbox.

Upvotes: 0

Views: 287

Answers (1)

Cristian Sanchez
Cristian Sanchez

Reputation: 32127

Change:

var ui=document.getElementById('same_info').value;

to

var ui=document.getElementById('same_info');

Also, I'm fairly certain it's onchange, not OnChange -- Javascript is case sensitive.

ui.onchange = valid;

Also note that if the user checks it, and unchecks it, it will still have those validation requirements even though it has been unchecked.

Upvotes: 1

Related Questions