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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to change the location.href

    This is a simplified example of what I'm trying to do:

    function myURL()
    {
    alert("function myURL executing");
    alert(location);
    location.href="http://www.google.com";
    alert(location);
    }
    ---
    <form name="queryForm" onSubmit="myURL()">
    <input type="submit" value="run myURL function">

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    New to list, sorry. I cannot get the javascript to change the URL. I've dumbed down what I'm trying to do but even that doesn't work. I've tried rewriting the location.href, using location.reload() too but can't make it change. Any ideas? Thanks.
    Code:
    function myURL()
    {
    alert("function myURL executing");
    alert(location);
    location.href="http://www.google.com";
    alert(location);
    }
    ---
    <form name="queryForm" onSubmit="myURL()"> 
    <input type="submit" value="run myURL function">

  • #3
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    you should just be able to use the 'action' attribute
    Code:
    <form name="queryForm" method="get" action="http://www.google.com/">

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    It is working for me. Both alerts execute before the page changes to google.com, and therefore both say the same thing, but then it goes to google.com successfully. What are you trying to make it do?


  •  

    Posting Permissions

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