PDA

View Full Version : Javascript- Simple question FF x ie7



mad
01-09-2008, 07:25 PM
Hello,

This piece of code:

<script type="text/javascript">
function Choice()
{
window.location=document.getElementById("drpdwn").value;
}
</script>

and

<form>
<select name="select" id="drpdwn" onchange="Choice()">
<option>--PLEASE CHOOSE ONE OF THE TWO POSSIBLE OPTIONS--</option>
<option value="HTML1.html">OPTION 1</option>
<option value="HTML2.html">OPTION 2 </option>
</select>
</form>

-------------------------------------------------------------------------
works fine under Firefox but not under ie7.

The reason is the windows.location in the javascript.

I tried windows.location.href and it doesn't work either.

QUESTION:

What are my options to make this code work in both IE7 and FF?


Thank You for any possible help

tech_support
01-10-2008, 02:09 AM
Change this:


document.getElementById("drpdwn").value;
to this:

document.getElementById('drpdwn').options[document.getElementById('drpdwn').selectedIndex].value

codeexploiter
01-10-2008, 03:53 AM
Change this:


document.getElementById("drpdwn").value;
to this:

document.getElementById('drpdwn').options[document.getElementById('drpdwn').selectedIndex].value

It is not necessary IE7 and IE6 definitely supports the following method:



document.getElementById("drpdwn").value;


I've tried the code and it is working correctly for me in both IE7 and IE6, find the pasted code below:



<form>
<select name="select" id="drpdwn" onchange="Choice();">
<option>--PLEASE CHOOSE ONE OF THE TWO POSSIBLE OPTIONS--</option>
<option value="HTML1.html">OPTION 1</option>
<option value="HTML2.html">OPTION 2 </option>
</select>
</form>

<script>
function Choice(){
//alert(document.getElementById('drpdwn').value);
window.location = document.getElementById('drpdwn').value;
}
</script>





The reason is the windows.location in the javascript.

I tried windows.location.href and it doesn't work either.


In both references you've used windows.location and windows.location.href but it is window.location and window.location.href

tech_support
01-10-2008, 04:15 AM
It is not necessary IE7 and IE6 definitely supports the following method
But it's not standard JavaScript... I think. My method works on all browsers.

codeexploiter
01-10-2008, 05:41 AM
But it's not standard JavaScript... I think. My method works on all browsers.

What makes you think it is not a standard technique. if you want to get the text of the selected item from a select box then I think we have to used the selectedIndex property.

Tested my method in the following browsers and working correctly.

netscape 8.1.2
Opera 9.25
IE 7
IE 6
FF 2.0.11
Flock 1.0.5
Safari 3.0.4

tech_support
01-11-2008, 01:19 AM
So why aren't they using it on most websites??

mad
01-11-2008, 02:03 AM
It is not necessary IE7 and IE6 definitely supports the following method:



document.getElementById("drpdwn").value;


I've tried the code and it is working correctly for me in both IE7 and IE6, find the pasted code below:



<form>
<select name="select" id="drpdwn" onchange="Choice();">
<option>--PLEASE CHOOSE ONE OF THE TWO POSSIBLE OPTIONS--</option>
<option value="HTML1.html">OPTION 1</option>
<option value="HTML2.html">OPTION 2 </option>
</select>
</form>

<script>
function Choice(){
//alert(document.getElementById('drpdwn').value);
window.location = document.getElementById('drpdwn').value;
}
</script>





In both references you've used windows.location and windows.location.href but it is window.location and window.location.href



Thanks a lot. The code worked in IE7 and FF. :)


Now the interesting note:
In IE7 I can't have any javascript code in the <head></head> with exception of the validation code generated by Dreamweaver.

When the page is loaded, the message restricting scripts and ActiveX execution is shown. I allow scripts and the first thing I get is and ERROR MESSAGE:

Line: line #
char: 1
syntax error
code 0
:confused:

I had a JavaScript code that checked if I'm in IE.
By deleting that code, the error message is not issued anymore.

This is not a problem per se, but it's kind of weird getting this message.

Just F.Y.I