Results 1 to 7 of 7

Thread: Javascript- Simple question FF x ie7

  1. #1
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Javascript- Simple question FF x ie7

    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

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Change this:
    Code:
    document.getElementById("drpdwn").value;
    to this:
    Code:
    document.getElementById('drpdwn').options[document.getElementById('drpdwn').selectedIndex].value
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by tech_support View Post
    Change this:
    Code:
    document.getElementById("drpdwn").value;
    to this:
    Code:
    document.getElementById('drpdwn').options[document.getElementById('drpdwn').selectedIndex].value
    It is not necessary IE7 and IE6 definitely supports the following method:

    Code:
      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:

    Code:
    <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>

    Quote Originally Posted by mad
    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

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    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.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by tech_support View Post
    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
    Last edited by codeexploiter; 01-10-2008 at 05:16 AM. Reason: added more information

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    So why aren't they using it on most websites??
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by codeexploiter View Post
    It is not necessary IE7 and IE6 definitely supports the following method:

    Code:
      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:

    Code:
    <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


    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
    Last edited by mad; 01-11-2008 at 01:06 AM. Reason: Bold/red in text

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •