PDA

View Full Version : Dynamic select options: Strange FF error


Mhtml
02-08-2006, 04:21 PM
Perhaps someone can explain to me why, if I try to gain a reference to a select element in firefox (1.0.7) that if that element has no option child elements I cannot get a handle?

In IE I can get a handle, and even push child elements onto the options array however in FF I can't even get a reference to the select element object.

Crazy. I haven't tested in a later FF version yet, I'll upgrade later today. Perhaps it is a bug? I searched bugzilla and found no bugs listed so perhaps I may be the first to find it, or I could just be missing something as I am no js expert.

dep
02-08-2006, 04:22 PM
Some sourcecode could help to see what's going on there.

Mhtml
02-09-2006, 07:54 AM
Well like I said, getting a reference to a select element with no child options-

<form name="myform">
<select name="selobj"></select>
</form>
<script>
var frm = document.forms['myform'];
var obj = frm.selobj.options;
</script>


In FF 1.0.7 you should get frm has no properties.

However if you add an option element-

...
<select name="selobj">
<option>opt</option>
</select>
...

Then no error is thrown. In IE it works, also works in 1.5.0.1 as I just tested so obviously it is a bug, or was.

Kor
02-09-2006, 09:06 AM
It works for me when using onload to reference the select:
It don't understand quite well the nature of your problem...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var sel;
onload=function(){
sel = document.getElementById('selobj');
alert(sel.id)
}
</script>
</head>
<body>
<select name="selobj" id="selobj"></select>
</body>
</html>

Mhtml
02-09-2006, 03:38 PM
Try get the options array, and create an option. This is in FF 1.0.7 of course.

Kor
02-09-2006, 03:50 PM
Try get the options array, and create an option

To create an option I don't need to get the options array. Study DOM 1(or 2) level createElement() and appendChild() methods.... Need an example?

Mhtml
02-09-2006, 04:06 PM
No I looked it up, however try doing what I've said. FF 1.0.7 will not do it, whereas IE and FF 1.5.0.1 will

Kor
02-09-2006, 05:20 PM
Strange... You make me install the FF 1.0.7 again... Well, if so, why not create the select object as well using DOM?

Mhtml
02-09-2006, 05:31 PM
Oh I have no problem doing that, I just came across this particular error and it made me wonder.