Property not supported

H

haggardii

I'm stumped! I have two identical (as far as I can tell) <SELECT>'s
and I try to access their values with the same function. It works in
FireFox, but in IE it throws an error "Object doesn't support this
property or method." But it only throws the error on the second call
to the function (for <SELECT id=sortorder>) So it accepts the call for
<SELECT id=timespan> but not for <SELECT id=sortorder>

-----HTML-----
<SELECT name=timespan id=timespan style="background-color:
#5681AC; color: #FFFFFF; border: 1px solid #2f455c; padding: 2px;
text-align:left; font-weight: bold; outline-style: none;"
onChange="javascript:startover('restart');">
<OPTION value="86400">Past 24 hours</option>
<OPTION value="43200">Past 12 hours</option>
<OPTION value="28800">Past 8 hours</option>
<OPTION value="3600">Past hour</option>
<OPTION value="1800">Past 30 minutes</option>
<OPTION value="600">Past 10 minutes</option>
</select>
<SELECT name=sortorder id=sortorder style="background-color:
#5681AC; color: #FFFFFF; border: 1px solid #2f455c; padding: 2px;
text-align:left; font-weight: bold; outline-style: none;"
onChange="javascript:startover('restart');">
<OPTION value="quant">Quantity</option>
<OPTION value="severe">Severity</option>
</select>

-----JavaScript-----
timediff = WhatValSel('timespan');
sortorder = WhatValSel('sortorder'); // Here's where it throws the
error

function WhatValSel(selid) {
var tmp = document.getElementById(selid).selectedIndex;
return document.getElementById(selid).options[tmp].value;
}

Why do I only get an error on the second call to WhatValSel and not the
first?
 
R

Richard Cornford

(e-mail address removed) wrote:
timediff = WhatValSel('timespan');
sortorder = WhatValSel('sortorder'); // Here's where it throws the
<snip>

IE's habit of making IDed elements into properties of the global object
means that the global object will have 'timespan' and 'sortorder'
properties referring to the two IDid elements. Assigning to a property
of the global object called - timediff - is not a problem as a new
property is created in the process. However, when you assign to -
sortorder - you are effectively trying to write to one of the
properties that IE has already created, and it will not let you replace
the value of that property.

The issue can be avoided by; declaring the global variables you use
with the - var - keyword, using non-global variable or changing the
name of the global sortorder property you use so that it does not
correspond with the ID of any HTML elements.

Richard.
 
H

HaggMan

ooooooohhhhh...

I wonder how many times I'll re-discover this before I'll remember (I
think this is the 3rd or 4th time)

Thank you for helping the absent-minded...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top