Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another way to write this piece of validation?

Status
Not open for further replies.

Sam6284

Programmer
Apr 24, 2002
16
FR
Yesterday it was a style issue. Today it's radio buttons. I'm shocked to discover such incompatibility exists between IE and NS on what seem to me to be common tasks.

The following code performs as expected in IE, but not NS6. In NS6, the function gets called because I get the first alert. It seems as though the OR statement doesn't get evaluated.

All I need to know is if the user has checked either option. Any ideas on another approach?

(BTW, NS6 validates the other elements such as input boxes and select lists.)

<html>
<head>
<title>Test</title>
<script language=&quot;JavaScript1.2&quot; type=&quot;text/javascript&quot;>
function ValidateForm(f) {
alert (&quot;Function Called&quot;);
if ((f.TestA[0].checked) || (f.TestA[1].checked)){
alert (&quot;Something Checked&quot;);
} else {
alert (&quot;Nothing Checked&quot;);
}
}
</script>
</head>
<body>
<table border=&quot;1&quot; cellpadding=&quot;5&quot;>
<form method=&quot;POST&quot; action=&quot;&quot; onSubmit=&quot;ValidateForm(this)&quot;>
<tr>
<td>Make a Choice</td>
<td>
Yes<input id=&quot;TestA&quot; name=&quot;TestA&quot; type=&quot;radio&quot; value=&quot;Yes&quot;>
No<input id=&quot;TestA&quot; name=&quot;TestA&quot; type=&quot;radio&quot; value=&quot;No&quot;>
</td>
<td><input type=&quot;submit&quot; id=&quot;TestForm&quot; name=&quot;TestForm&quot; value=&quot;Test Function&quot;></td>
</tr>
</form>
</table>
</body>
</html>
 
The statement should be like this:
if (f.TestA[0].checked || f.TestA[1].checked)

I have not failed; I merely found 100,000 different ways of not succeding...
 
No change - both evaluate to either true or false. I tried a few experiments, though. Maybe this will be of help:

If I change that first alert to alert (f); , IE returns [object] and NS returns [object HTMLFormElement] - both meaning the same thing.

However, if I change the alert to alert (f.TestA[0].name);, IE returns TestA, the expected result while NS returns nothing.

It seems NS doesn't understand f.TestA[n]. This is perplexing to me because in other parts of the validation code, it understands f.LoanAmt.value for <select> and f.DownPymt.value.length for <input type=&quot;text&quot;>
 
a crazy idea, but try
 if ((f.TestA[0].checked == true) || (f.TestA[1].checked == true)) --------------------------------------------------
Goals are dreams with deadlines
 
the following is a &quot;copy and paste&quot; piece of code out of one of my pages. it definitely works for both IE and NS
Code:
for (i=0; i<f.ProofType.length; i++) {
 if (f.ProofType[i].checked == true) {
  ProofTp = true
 }
}

that's why i suggested you try the &quot;== true&quot; thing.

what version of NS rae you using? --------------------------------------------------
Goals are dreams with deadlines
 
valeriav,

Amazing. The code you pasted from your application is the exact same code I started with! (The form I'm validating has about 30 radio buttons so I wrote that function to which I could simply pass the individual controls.) I only started playing around with my code because the first version I wrote (your version) wasn't working.

Since you've tested it in NS and there are other employees logged on now, I re-ran all the versions I've tested. They all work under NS4.3 and NS4.7.

That led me to believe I must have a bad install of NS6.2.3. I only installed it yesterday to do this testing. I've just finished removing, re-downloading and re-installing everything. No change! None of the tests work under NS6 on my box.

I guess my next step will to be to try loading NS6 on someone else's box.

Which leads me to another question: I haven't had to do version testing until now. Is there some place I can get older versions of IE and NS? (Every PC here will be replaced before year end. I won't have any older IE or NS versions around.) How do you other developers do your testing?

Thanks, everyone for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top