Forum Moderators: open

Message Too Old, No Replies

Mozilla Option Selected bug?

The selected option changes on refresh

         

Jay_R

9:45 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



I'm having a problem with Mozilla. I have a list that has an option-select form field. I set the first option to selected. The page loads fine at first, but then, when it is refreshed, it goes to another option. Here's the code....

<form name="form1">
<select name="form1Select" onChange="optionChange()">
<option selected value="noAction">The first one</option>
<option value="noAction">The second one</option>
<option value="noAction">The third one</option>
<option value="noAction">The fourth one</option>
<option value="noAction">The fifth one</option>
<option value="noAction">The sixth one</option>
<option value="noAction">The seventh one</option>
<option value="noAction">The eight one</option>
<option value="noAction">The ninth one</option>
<option value="noAction">The tenth one</option>
<option value="noAction">The eleventh one</option>
<option value="noAction">The twelfth one</option>
</select>
</form>

<script language="javascript">
<!--
function optionChange()
{
return false;
}

//-->
</script>

If you change the value of the selected element to something unique, then it works fine until you change the selection, once you refresh the page it will do the same thing... I'm at a loss.. Any help is much appreciated...
I'm looking at this with Mozilla 1.4.
-Jay

BlobFisk

5:19 pm on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jay_R,

Is that the full code of the optionChange() function?

Jay_R

8:02 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



Thanks BlobFisk,

I just wanna say I've remember reading many of your pasts posts and they were very helpful...

That was just some skeleton JavaScript to make sure I had the option box working correctly.

I changed the first element name to something unique such as #noAction. The real option box had URL values and "#somethingToReflectNoChange" values. I added some script like this to deal with it....

function optionChange()
{
if (document.form1.form1Select[document.form1.form1Select.selectedIndex].value == "#noAction")// mozilla fix
{
// do something;
return false;
}
else if (document.form1.form1Select[document.form1.form1Select.selectedIndex].value == "noAction")
{
//do something;
return false;
}
else
location=document.form1.form1Select[document.form1.form1Select.selectedIndex].value;
}

I haven't tested it vigorously, but I think it stopped Mozilla from selecting a random option. However, like I said, I was just looking at it in Mozilla 1.4; it very well could have been fixed in a later version. Which brings me to the question of, what version of Mozilla should I test with? Other browsers? I can scan though the forums for this answer though...

You can let this one fade into oblivion, but if you can think of better approaches then I'm always interested...

Thanks again BlobFisk, your reply was appreciated.

BlobFisk

8:13 am on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey Jay_R,

It looks like you've left out options from your JS:

location=document.form1.form1Select.options[document.form1.form1Select.selectedIndex].value;

The correct (and full) code for getting a value from a select list is:


document.formName.selectName.options[document.formName.selectName.selectedIndex].value

OR

document.formName.getElementById('selectID').options[document.formName.getElementById('selectID').selectedIndex].value

HTH