Hi,

I'm trying to validate a checkbox in the form and I'm not sure which property to use. At the moment, I have a checkbox called "termsandcond" and I'm trying to write a javascript validation script that checks to see if it is ticked or not.

function validate(){
    
    var form = document.forms.bookingform;
    if(form.elements.termsandcond.value = false){
        alert('You must agree to the Terms And Conditions before booking.');
        return false;
    } 
    return true;
}

If anyone knows what properties I be using, or what I'm doing wrong, that would be really helpful.

Thanks in Advance
ForestTech

i think the property you're looking for is 'checked'..

I don't know whether forms.elements.xxx will give you a named object handle in return...

if your input is set up: <input name="termsandconds" type="check"/>, you should be able to access it as bookingform.termsandconds.

EDIT: I imagine both methods work though (document.forms.bookingform.elements.termsandconds | bookingform.termsandconds)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.