...

View Full Version : When validating checkboxes with different names, numbers in names kill the form



TeamKaeru
08-08-2006, 07:20 PM
When validating checkboxes with different names, numbers in names kill the form

Hello,

I have to create a validation for a number of checkboxes that have different names (I know it's best to have the same names for each, and I would love to... But I'm working with someone else's system on this one! ;) ). I can get it working if the names are simple text like in the below 'fred' or 'george' but when the names are actually these whacky code numbers that the system uses, it fails.

See examples below of what fails and what works. Any suggestions would be most welcome!

Does Not Work:
if (theForm.00N30c2Mw.checked == false && theForm.00N302wD.checked == false)
{
alert ('Please select at least one checkbox');
return false;
}

Does Work:
if (theForm.fred.checked == false && theForm.george.checked == false)
{
alert ('Please select at least one checkbox');
return false;
}

vwphillips
08-08-2006, 07:30 PM
name shoud strat with alpha character but


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
function Ck(){
if (!document.getElementsByName('00N30c2Mw')[0].checked&&!document.getElementsByName('00N302wD')[0].checked)
{
alert ('Please select at least one checkbox');
return false;
}
}
</script></head>

<body >
<form >
<input type="checkbox" name="00N30c2Mw" />
<input type="checkbox" name="00N302wD" /><input type="button" name="" value="Tst" onclick="Ck();" />
</form>
</body>

</html>

TeamKaeru
08-08-2006, 07:39 PM
It works like a charm now.


You are my hero :thumbsup:


Have a good week.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum