Help - Search - Members - Calendar
Full Version: select with one option
HTMLHelp Forums > Programming > Client-side Scripting
raphael75
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
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
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.html

In browsers with javascript disabled nothing of this will work, of course.
pandy
blink.gif

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. tongue.gif

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
QUOTE(pandy @ Nov 13 2007, 08:31 AM) *

blink.gif

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. unsure.gif
pandy
No, the length property of the select object, ot whatever it's called. That's what me thinks he's trying to do. tongue.gif

Something like
CODE
document.myForm.mySelect.length
raphael75
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
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? happy.gif
raphael75
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
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
QUOTE(raphael75 @ Nov 14 2007, 09:54 PM) *

BTW, what does OP mean?

Original Poster, at least I think so. blush.gif
raphael75
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.
Invision Power Board © 2001-2010 Invision Power Services, Inc.