Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts

    why window.location doesn't work in FF ?

    dears,

    am trying to redirect user from onchange event to another location in the page.
    its work fine in IE but not in firefox :-(

    why window.location doesn't work in FF ?

    Html:

    Code:
    <form name="forder">
    <select name="bycat" onchange="gocat()">
    <option value=1>one</option>
    <option value=2>two</option>
    <option value=3>three</option>
    </select>
    </form>
    javascript:

    Code:
    function gocat()
    {
     window.location ="index.php?show&cat=" + forder.bycat.options(forder.bycat.selectedIndex).value;
    }
    any idea????
    Last edited by marhoons; 07-14-2010 at 04:51 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,598
    Thanks
    80
    Thanked 4,498 Times in 4,462 Posts
    Technically, it should be location.href (the "window." is optional).

    Works for me all the time in all browsers.

    But so does window.location, so far as I know.

    But *probably* your actual problem is that you are using parentheses where square brackets are called for:
    Code:
    function gocat()
    {
     window.location ="index.php?show&cat=" + forder.bycat.options(forder.bycat.selectedIndex).value;
    }
    *ONLY* MSIE recognizes parentheses as indexers of the options.

    Try:
    Code:
    function gocat()
    {
        location.href ="index.php?show&cat=" + forder.bycat.options[forder.bycat.selectedIndex].value;
    }
    *however*...

    However all modern browsers also understand the ".value" of a <select> object, so long as it is not a <select multiple>. So you should be able to simply do:
    Code:
    function gocat()
    {
        location.href ="index.php?show&cat=" + forder.bycat.value;
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,598
    Thanks
    80
    Thanked 4,498 Times in 4,462 Posts
    And, finally, you could simplify this even further thus:
    Code:
    <form name="NOT NEEDED">
    <select name="NOT NEEDED" onchange="location.href='index.php?show&cat='+this.value;">
    <option value=1>one</option>
    <option value=2>two</option>
    <option value=3>three</option>
    </select>
    </form>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    window.location = "index.php?show&cat=" + document.forder.bycat.options[document.forder.bycat.selectedIndex].value;

    or simply

    window.location = "index.php?show&cat=" + document.forder.bycat.value;


    Old Pedant beat me to it! Why is he not in bed? FYI I am going on holiday today so you will not be troubled by me again for 10 days.

    Edit:
    <select name="bycat" onchange="gocat()">
    How does the user select option 1 onchange when One is the default?
    There must be an initial "option" 'Please select' and the gocat() script must filter that out.


    Expecting the world to treat you fairly because you are good is like expecting the bull not to charge because you are a vegetarian.
    Last edited by Philip M; 07-14-2010 at 06:42 AM.

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    24
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Old Pedant...
    Thanks alot, worked with me.
    i used (onchange="location.href='index.php?show&cat='+this.value).

    Thanks again for great help.

    Thanks Philip M too..

    wish u all the best.


  •  

    Posting Permissions

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