Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,296 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 870 people online right now. Registration is fast and FREE... Join Now!




checkbox validation

 
Reply to this topicStart new topic

checkbox validation

sushama
26 Nov, 2008 - 02:27 AM
Post #1

New D.I.C Head
*

Joined: 26 Nov, 2008
Posts: 3

Hi,
Here is the code for checkbox validation
I think there is a problem with 'return' statements.
As validation for textbox works fine but for checkbox it won't.
After clicking all checkboxes it shows alert message alert(Select user)....Please help me...
Thank you smile.gif

function Vailidate(form)
{
'validate textbox
var total = 0;
if (form.taskdescr.value == '')
{
alert('Task Description is required.');
return (false);
}
'validate chkbox
var node_list = document.getElementsByTagName('input');
var chkboxes = [];
for (var i = 0; i < node_list.length; i++)
{
var node = node_list[i];
if (node.getAttribute('type') == 'checkbox')
{
chkboxes.push(node);
}
}
if (!chkboxes.checked)
{
alert('select user');
return false;
}
else
{
alert('selected');
}
}

User is offlineProfile CardPM
+Quote Post


xerxes333
RE: Checkbox Validation
26 Nov, 2008 - 06:08 AM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Jul, 2007
Posts: 430



Thanked: 23 times
Dream Kudos: 25
My Contributions
For future refrence
code.gif

Try this . . .
CODE
function Vailidate(form){
    //validate textbox
    var total = 0;
    if (form.taskdescr.value == ''){
        alert('Task Description is required.');
        return (false);
    }
    //validate chkbox
    var node_list = document.getElementsByTagName('input');
    var allChecked = 0;
    for (var i = 0; i < node_list.length; i++){
        var node = node_list[i];
        if (node.getAttribute('type') == 'checkbox'){
            if(!node_list[i].checked)
                return(false);
        }
    }
}
    

User is offlineProfile CardPM
+Quote Post

sushama
RE: Checkbox Validation
26 Nov, 2008 - 11:35 PM
Post #3

New D.I.C Head
*

Joined: 26 Nov, 2008
Posts: 3

Hi xerxes333 biggrin.gif ,
I appreciate your quick response and help. thankx
But this code is not working means it is not taking any action on clicking 'submit' button.....



QUOTE(xerxes333 @ 26 Nov, 2008 - 06:08 AM) *

For future refrence
code.gif

Try this . . .
CODE
function Vailidate(form){
    //validate textbox
    var total = 0;
    if (form.taskdescr.value == ''){
        alert('Task Description is required.');
        return (false);
    }
    //validate chkbox
    var node_list = document.getElementsByTagName('input');
    var allChecked = 0;
    for (var i = 0; i < node_list.length; i++){
        var node = node_list[i];
        if (node.getAttribute('type') == 'checkbox'){
            if(!node_list[i].checked)
                return(false);
        }
    }
}
    



User is offlineProfile CardPM
+Quote Post

JMRKER
RE: Checkbox Validation
27 Nov, 2008 - 06:36 AM
Post #4

D.I.C Head
**

Joined: 25 Oct, 2008
Posts: 135



Thanked: 15 times
My Contributions
QUOTE
But this code is not working means it is not taking any action on clicking 'submit' button.....

Post a link to the rest of your code as the error may be elsewhere.
BTW, have you looked at the error console in FF.
What browser are you using?

User is offlineProfile CardPM
+Quote Post

sushama
RE: Checkbox Validation
28 Nov, 2008 - 02:49 AM
Post #5

New D.I.C Head
*

Joined: 26 Nov, 2008
Posts: 3

QUOTE(JMRKER @ 27 Nov, 2008 - 06:36 AM) *

QUOTE
But this code is not working means it is not taking any action on clicking 'submit' button.....

Post a link to the rest of your code as the error may be elsewhere.
BTW, have you looked at the error console in FF.
What browser are you using?


CODE

Hi,
I have tested the code sent by xerxes333 on FF,IE+7 and Opera also, but it's not working.



User is offlineProfile CardPM
+Quote Post

xerxes333
RE: Checkbox Validation
28 Nov, 2008 - 09:57 AM
Post #6

D.I.C Regular
Group Icon

Joined: 5 Jul, 2007
Posts: 430



Thanked: 23 times
Dream Kudos: 25
My Contributions
The code works just fine if you call it properly. In your FORM tag you need to add this attribute
onSubmit="return Validate(document.getElementById('myForm'))"
obviously substituting the document.getElementById('myForm') for your form node.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 04:37PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month