Forum Moderators: open

Message Too Old, No Replies

Why doesn't this work in IE?

object.options[object.selectedIndex].value;

         

kevinkp7

7:48 pm on Apr 24, 2009 (gmt 0)

10+ Year Member



This works fine in FF but not IE - go figure. Is there something with select and options that IE doesn't like?

Here's my code:

<script type="text/javascript">

var lastGroup='<?php echo $member_group_ID; ?>';
var lastSemester='<?php echo $member_country_name; ?>';

function changeCountry(country, semester, form){
<!--
var cValue = country.options[country.selectedIndex].value;
var sValue = form[semester].options[form[semester].selectedIndex].value;
var thisGroup=cValue+' '+sValue;

document.getElementById(form[lastGroup].id).style.display='none';
document.getElementById(form[lastSemester].id).style.display='none';

document.getElementById(form[semester].id).style.display='';

document.getElementById(form[thisGroup].id).style.display='';
document.getElementById(form[thisGroup].id).focus();
document.getElementById(form[thisGroup].id).style.border='1px solid #c60';

lastGroup=thisGroup;
lastSemester=semester;
-->
}

function goto_URL(object) {
window.location.href = 'blog.php?id='+object.options[object.selectedIndex].value;
}

</script>

This code uses 3 selects - the first is country, the second is semester, and the third is students. I run one php query to get all the students and separate them in group specific <select>s -- this code will show/hide the appropriate <select>s as you select through the country and semester using

onchange="changeCountry(this.form.selectCountry, this.form.selectCountry.options[this.form.selectCountry.selectedIndex].text, this.form);"
(the semester selects are named after the country - hence the selectCountry.text)

Then the student selects are named by the combined values of the selected Country and selected Semester. Their onchange code is this:

onchange="goto_URL(this.form['<?php echo $student_group_ID; ?>'])"

Like I said - it works perfectly in Firefox but not at all in IE.

DrDoc

9:04 pm on Apr 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which version of IE?

astupidname

4:35 pm on Apr 25, 2009 (gmt 0)

10+ Year Member



When referencing a selects selected options value, should use (where select is the select object itself):
select.options[select.options.selectedIndex].value

kevinkp7

1:14 pm on Apr 27, 2009 (gmt 0)

10+ Year Member



@DrDoc - sorry, doesn't work in IE6 or IE7

@astupidname - Thanks! I'll check it out!