User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 392,074 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,135 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3256 | Replies: 1 | Solved
Reply
Join Date: Nov 2006
Posts: 23
Reputation: ForestTech is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ForestTech ForestTech is offline Offline
Newbie Poster

Simple checkbox validation question

  #1  
Nov 27th, 2006
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
Last edited by ForestTech : Nov 27th, 2006 at 6:31 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 936
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Posting Shark

Re: Simple checkbox validation question

  #2  
Nov 27th, 2006
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)
Last edited by MattEvans : Nov 27th, 2006 at 6:59 pm.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 12:09 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC