Please help: Reload window with new url problem :confused:

Discussion in 'JavaScript' started by JOYMachine, May 26, 2011.

  1. #1
    I tried changing so much, but I got stuck. It works when I comment out window.location and leave just alert. It alerts me fine with correct url. It just does not want to open that url! :confused:

    You can see the actual attempt here: http://ronimarinkovic.com/dina/location.html

    Code I'm using is:
    function convertURL() { 
      var url = document.getElementById('start').value; 
      if (url=='') { alert('Enter Starting point.'); return false; } 
      var final_url; 
      final_url = 'http://maps.google.com/maps?saddr='+ url +'&daddr=43.26292335379714,16.65346437622564';  
      //window.location = final_url; 
      //alert(final_url); 
      window.location.replace( final_url );
    } 
    
    Code (markup):
    <form name="SearchForm" action="" onsubmit="return convertURL(this);"> 
    <label id="label1">Get directions from (city, country) </label>
    <input id="start" name="text1" type="text" /> to Bol apartments Dina 
    <input id="directions" name="Button1" type="submit" value="Get Directions" />
    </form>
    
    Code (markup):

     
    JOYMachine, May 26, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    try

    window.location.href=final_url
     
    Jan Novak, May 26, 2011 IP
  3. JOYMachine

    JOYMachine Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    48
    #3
    tried... and tried again and again...
    window.location
    window.location.href
    window.location.open
    window.location.replace

    Confusing is that when I leave alert, it alerts me with proper ly created url, and when I want to open that url it just adds ?text1=Padova%2CItaly&Button1=Get+Directions arguments to parent url!?!?!
     
    JOYMachine, May 26, 2011 IP
  4. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Ahh, your form is submitted. Try this:
    
    function convertURL() { 
      var url = document.getElementById('start').value; 
      if (url=='') { alert('Enter Starting point.'); return false; } 
      var final_url; 
      final_url = 'http://maps.google.com/maps?saddr='+ url +'&amp;daddr=43.26292335379714,16.65346437622564';  
      //window.location = final_url; 
      //alert(final_url); 
      window.location.href= final_url ;
      return false;
    }
    
    Code (markup):
    I didn't test this code, but something like this should work.
     
    Jan Novak, May 26, 2011 IP
  5. JOYMachine

    JOYMachine Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    48
    #5
    Wow! Worked like a charm :)
    Thank you so much for taking time to help.
     
    JOYMachine, May 27, 2011 IP