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
    Mar 2010
    Location
    Australia
    Posts
    93
    Thanks
    38
    Thanked 0 Times in 0 Posts

    redirect to new page

    Hi,
    I have a form in which i have a dropdown list and a submit button. I want to code so that when users select the value from the dropdown list, it should redirect then to the specified page. For instance i have the value, "car", "House" and "pets" in my dropdown listbox, if a use click on "car" it should redirect them to the car page. I have done the following code, but something seems not to work
    Code:
    <script type="text/javascript">
    function move(){
    if (document.sell.cat.value == 'Cars'){
    window.location = 'http://www.yourdomain.com'
    }
    </script>
    and in the submit button am calling the function move()
    Code:
    <input type="submit" name="button2" id="button2" value="Search" onclick="move()"/>
    my form name is sell and the dropdown list menu is cat.
    Thanks
    Last edited by avizhome; 03-30-2010 at 06:25 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    You can do it much more simply than that:
    Code:
    <select onchange="location.href=this.value;">
    <option value="#">--choose one--</option>
    <option value="http://www.espn.com">Sports</option>
    <option value="http://www.cnn.com">News</option>
    <option value="cats.html">Kitties</option>
    <option value="canines.html">Dogs</option>
    </select>
    Your user doesn't even need to click on a submit button. Simpler user interface.
    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,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Oh...and your problem is that you used a *SUBMIT* button!

    So it tries to change the URL via the JavaScript code, but then the normal action of the SUBMIT button takes over and posts the <form> right back to this page.

    If you would just change type="submit" to type="button" I bet it would work.
    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.

  • Users who have thanked Old Pedant for this post:

    avizhome (03-30-2010)

  • #4
    New Coder
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    93
    Thanks
    38
    Thanked 0 Times in 0 Posts
    awesome thanks ....both ur solution were perfect

  • #5
    New Coder
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    93
    Thanks
    38
    Thanked 0 Times in 0 Posts
    can we call more then a function on body load?
    am trying this but it doesn't work
    Code:
    <body onload="MM_preloadImages('images/home_2.jpg','images/cars_2.jpg','images/real_state_2.jpg','images/computers_2.jpg','images/usp_2.jpg','images/jobs_2.jpg','images/dating_2.jpg','images/contact_2.jpg');fillCategory()">
    my fillcategory function:
    Code:
    <script language="javascript" >
    function fillCategory(){ 
    addOption(document.register.country, "Fiji", "Fiji", "");
    addOption(document.register.country, "Australia", "Australia", "");
    addOption(document.register.country, "New Zealand", "New Zealand", "");
    }
    </script>


  •  

    Posting Permissions

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