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!

Compatibility issue with simple script, does not work in IE 1

Status
Not open for further replies.

electricphp

Programmer
Feb 20, 2008
71
US
I have this little script that works fine in firefox but not IE:

Code:
var dropdownIndex = document.getElementById('ship').selectedIndex;
var dropdownValue = document.getElementById('ship')[dropdownIndex].value;
	
    document.getElementById("siteTotal").innerHTML = dropdownValue;

it is invoked by

Code:
<select name="shipvalues" id="ship" onChange="setFees();">

what could be the problem?
 
It works for me in IE8. Which version of IE is giving you trouble?

With that said, how about doing it in a simpler fashion:
Code:
var dropdownValue = document.getElementById('ship').value;

You really don't need to get the selected index first, and then use that to get the value. Just ask for the control's value directly. Which will be the value of the selected option.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
You may also want to try giving the same name and id to the select. Something like this:

Code:
<select name="ship" id="ship" onChange="setFees();">
 
I am using IE8.

this works in FF:

var dropdownValue = document.getElementById('ship').value;

but not in IE.

however if I do something like this:

var dropdownValue = document.getElementById('ship').selectedIndex;

it will show 0, 1, 2...etc in IE

I already tried setting the name and id both to "ship" but that didn't do anything.

 
Well as I said, it works for me in IE8, so its something else.

Is there more code between the point you get the value and the point where you set the innerHTML value with it?

What kind of element is "SiteTotal"?






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
<span id="siteTotal"></span>

That's all the code.

I may switch to radio boxes if I can't get this to work.
 
I just tried this and like Phil everything runs fine even for me in IE8. Are you sure that the JS is being executed at your end? Could it be that your IE's JS security settings are blocking it?
 
Do you have any styles applied to the span that may be hiding the text?

Anyway I've tried it with your original code as is, or my version, and it works fine in IE8.

Is IE maybe returning an error?





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Your <options> have no value attributes. FF uses the text from the option as a value, but IE needs the value to be set.

since there is no value, IE actually does it right this time and returns a blank.
Code:
<options [red]value="some value"[/red]> Option display</option>



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top