raphael75
Nov 12 2007, 04:47 PM
I have a page that has a <select> with the <option>s coming in dynamically from a database. The select has only a single option. FF 2.0.0.9 and IE7 are both treating this select as having an undefined length. Is this supposed to happen? Is there a workaround or some was to return the length of 1? Thanks.
pandy
Nov 12 2007, 05:20 PM
QUOTE(raphael75 @ Nov 12 2007, 10:47 PM)

Is this supposed to happen?
No. How to you access it? Please show a sample.
Christian J
Nov 12 2007, 07:09 PM
Could be a browser bug, while older browsers may not support it at all or even crash IIRC. A quick googling turned up this version with special treatment for IE:
http://www.mredkj.com/tutorials/tutorial005.htmlIn browsers with javascript disabled nothing of this will work, of course.
pandy
Nov 13 2007, 02:31 AM
Isn't the OP trying to
get the
length of the option? That works in all browsers. Well, haven't tested in older than Netscape 4.
If that's the case one cause for error could maybe be that JS tries to read the value before the option is populated. But I think that would return null rather than undefined. As said, a sample page would be helpful
Christian J
Nov 13 2007, 06:29 AM
QUOTE(pandy @ Nov 13 2007, 08:31 AM)

Isn't the OP trying to
get the
length of the option?
You mean the LENGTH attribute of the SELECT element? I don't quite understand
what the OP is asking.
pandy
Nov 13 2007, 06:52 AM
No, the length property of the select object, ot whatever it's called. That's what me thinks he's trying to do.
Something like
CODE
document.myForm.mySelect.length
raphael75
Nov 14 2007, 03:54 PM
Sorry for the confusion. Say you have something like this (I just threw this together as an example, it may not be perfect):
<html>
<head>
<script>
function somefunction()
{
alert(document.form1.sel1.length)
}
</script>
</head>
<body>
<form name="form1">
<select name="sel1">
<option value="yay" onclick="somefunction()">my option</option>
</select>
</form>
</body>
</html>
It would alert "undefined". But if I added a second <option>, it alerts me "2".
Thanks for your help! BTW, what does OP mean?
pandy
Nov 14 2007, 04:13 PM
Yeah? That works if the script is called after the form is loaded. If called prematurely it returns null and not undefined. Can we see the sample now?
raphael75
Nov 14 2007, 05:05 PM
By sample, are you saying you want to see a screenshot of the actual page I'm working on, or the *actual* code?
Darin McGrew
Nov 14 2007, 05:22 PM
The most useful information I've gotten from a screenshot has been the URL where I could see what's really going on.
Christian J
Nov 14 2007, 05:35 PM
QUOTE(raphael75 @ Nov 14 2007, 09:54 PM)

BTW, what does OP mean?
Original Poster, at least I think so.
raphael75
Nov 16 2007, 02:06 PM
The file was on one of our internal staging servers that doesn't have public access. Unfortunately, I can't give out the address. But the example script I created did exactly the same thing, so I was hoping it could be used instead.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.