views:

36

answers:

1

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.

+1  A: 

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.

CD Sanchez
thanks for answering,i did what you advise , but its not working.
priyambika