Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: open

Message Too Old, No Replies

Checkbox validation

     
6:00 pm on Oct 14, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 4, 2005
posts:621
votes: 0


I always struggle with this one. This isn't working in IE.

function validateReport(form)
{
var is_error = false;

var checkSelected = false;
for (var i = 0; i < document.getElementsByName('type[]').length; i++){
if (document.getElementsByName('type[i]').checked)
checkSelected = true;
}

if (document.getElementById('user').value == 0){

modContent('error_msg', '<i>*Please select a user for this report.</i>');
showElement('error_msg');
is_error = true;

}else if(!checkSelected){

modContent('error_msg', '<i>*Please select at least 1 type of record for your report.</i>');
showElement('error_msg');
is_error = true;

}else if (document.getElementById('start_date').value == ''){

modContent('error_msg', '<i>*Please enter a start date for your report.</i>');
showElement('error_msg');
is_error = true;


}else if (document.getElementById('end_date').value == ''){

modContent('error_msg', '<i>*Please enter an end date for your report.</i>');
showElement('error_msg');
is_error = true;

}

if (is_error == false){

hideElement('error_msg');

}

return is_error;

}

It gets stuck and doesn't realise one checkbox is ticked. Any help would be greatly appreciated, thanks!
6:34 pm on Oct 14, 2010 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4965
votes: 10



if (document.getElementsByName('type[i]').checked)


Is probably supposed to be:

if (document.getElementsByName('type[' + i + ']').checked)
7:02 pm on Oct 14, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 4, 2005
posts:621
votes: 0


Nope that's not it but thanks, still gets stuck. FF doesn't give an error either.
10:02 am on Oct 15, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 4, 2005
posts:621
votes: 0


Got it now, thanks for the help Fotiman!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members