PDA

View Full Version : Mac IE problem


craigh@mac.com
10-24-2002, 03:49 AM
Hello-

I've got this little function here that works on PC IE, PC Mozilla & Mac Mozilla, but NOT Mac IE. Any idea why? I think it must have something to do with the indicated line because I've tried changing the other lines with no change in behavior.


<SCRIPT Language="javascript">
function assureUnique(val,num) {
for (var i=1; i<=5; i++) {
if (i!=num && document.label.elements['sortby['+i+']'].value==val) {
document.label.elements['sortby['+i+']'].value=""; //**this line
}
}
}
</SCRIPT>
<select name="sortby[1]" onChange="assureUnique(this.value,1)">
<option value=""></option>
<option value="zip" SELECTED>Zip Code</option>
<option value="member.last_name">Director Last name</option>
<option value="member.first_name">Director First name</option>
<option value="school.school_name">School name</option>
<option value="school.school_id">School number</option>
<option value="school.district_code">MSBOA District</option>
</select><BR>then >>
<select name="sortby[2]" onChange="assureUnique(this.value,2)">
<option value="" SELECTED></option>
<option value="zip">Zip Code</option>
<option value="member.last_name">Director Last name</option>
<option value="member.first_name">Director First name</option>
<option value="school.school_name">School name</option>
<option value="school.school_id">School number</option>
<option value="school.district_code">MSBOA District</option>
</select>
... there are 5 of these...

joh6nn
10-24-2002, 07:40 PM
what does it do that it shouldn't, or conversely, what doesn't it do that it should?

craigh@mac.com
10-24-2002, 08:46 PM
sorry - I assumed the function was self explanatory. The function is supposed to compare the value from the changed select-box to the values in 4 other select-boxes and change matches to a blank value ("") so that only one of the 5 select-boxes has that value (assureUnique). The Mac IE version doesn't change the others to black, it leaves them at their current value.

joh6nn
10-24-2002, 10:11 PM
well, i figured that's what you were trying to do, but i always like to ask and be sure.

i'm surprised that this is working in Moz; it shouldn't be. You don't selectboxes with their value property ( i'm actually not even sure they have a value property ). you set them using the selectedIndex property. you read from them, by sticking selectedIndex into the selectbox's options array, and reading that options value.

example:

selectedValue = document.FormName.SelectBox.options[document.FormName.SelectBox.selectedIndex].value;

document.FormName.SelectBox.selectedIndex = -1; //nothing selected
document.FormName.SelectBox.selectedIndex = 0; //first option selected
document.FormName.SelectBox.selectedIndex = 1; //second option selected

craigh@mac.com
10-24-2002, 10:35 PM
Well, I don't know why Moz worked, but it did. Your suggestions however have completely solved the problem. This is now what I am using:

function getListValue(field) {
var listValue = '';
if (field.selectedIndex != -1) {
listValue = field.options[field.selectedIndex].value;
}
return (listValue);
}
function assureUnique(val,num) {
for (var i=1; i<=5; i++) {
if (i!=num && getListValue(document.label.elements['sortby['+i+']'])==val) {
//document.label.elements['sortby['+i+']'].value="";
document.label.elements['sortby['+i+']'].selectedIndex=0;
}
}
}

I actually had the first function lying around, and you can see that I modified the second to just use the selectedIndex.

Thanks a lot for your assistance. I appreciate it!

craig:thumbsup: