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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with .length in Netscape.

Status
Not open for further replies.

JulieM

Programmer
Jun 6, 2001
25
0
0
GB
The function below works fine in IE but in Netscape the variable num is set to 'undefined'. Can anyone help I cannot find the answer as to what I need to do for Netscape.

Julie.


function showcheckboxvalue(oControl) {
var num = oControl.length;
for (var i=0; i<num; i++)
if (oControl.checked) {
if (oControl.value == &quot;CarParking&quot;) {
if (document.fmGetPropertyDetails.sCarParkingSpaces.value == &quot;-1&quot;) {
alert (&quot;The number of Car Parking Spaces must be selected!&quot;);
return false;
}
}
if (oControl.value == &quot;Other&quot;) {
if (document.fmGetPropertyDetails.tbOther.value == &quot;&quot;) {
alert (&quot;The 'Other' facilities must be specified!&quot;);
return false;
}
}
if (oControl.value == &quot;Adapted&quot;) {
var num2 = document.fmGetPropertyDetails.cbAdaptedNeed.length;
var count = 0;
for (var x=0; x<num2; x++)
if (document.fmGetPropertyDetails.cbAdaptedNeed[x].checked) {
count++
}
if (count == 0) {
alert (&quot;At least one adapted need must be specified!&quot;);
return false;
}
}
}
return true;
}
 
Change:

var num=oControl.length to var num=oControl.value.length

Tested with Netscape 7.0

MrGreed

&quot;did you just say Minkey?, yes that's what I said.&quot;
 
Thanks for the answer MrGreed have tried this already and have tried again but it doesn't work. The Netscape browser I am using is Version 7.1. Anymore suggestions.

Julie
 
Are you returning a value, check if you are even getting a value back alert(oControl.value);

if you are getting a value back you could try:

var strChk=String(oControl.value);
alert(strChk.length);

See if getting the length this way works for you. Also would be nice to see how you have the HTML code for the checkbox calling the showcheckboxvalue function.


MrGreed

&quot;did you just say Minkey?, yes that's what I said.&quot;
 
Whoa...

Correct me if I'm wrong but it looks like you're trying to text the length of a check box:

if (oControl.checked)

Also, it looks as if you're using the same name (oControl) for both a check box AND a text input field.

If the above is true, fix those and MrGreed's first reply will work perfectly.

There's always a better way. The fun is trying to find it!
 
JulieM,

Probably save a lot of time, (if the above doesn't
solve your problem) to paste the whole form here in
the thread. So that we can see ref to form elements.


2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top