Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: open

Message Too Old, No Replies

Checkbox validation

     

Pico_Train

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

10+ Year Member



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

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

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




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


Is probably supposed to be:

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

Pico_Train

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

10+ Year Member



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

Pico_Train

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

10+ Year Member



Got it now, thanks for the help Fotiman!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month