homepage Welcome to WebmasterWorld Guest from 54.161.197.188
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Checkbox validation
Pico_Train




msg:4216820
 6:00 pm on Oct 14, 2010 (gmt 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!

 

Fotiman




msg:4216840
 6:34 pm on Oct 14, 2010 (gmt 0)


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


Is probably supposed to be:

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

Pico_Train




msg:4216847
 7:02 pm on Oct 14, 2010 (gmt 0)

Nope that's not it but thanks, still gets stuck. FF doesn't give an error either.

Pico_Train




msg:4217087
 10:02 am on Oct 15, 2010 (gmt 0)

Got it now, thanks for the help Fotiman!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved