Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How to get value from input field into link as a variable
Old 07-02-2009, 09:36 AM How to get value from input field into link as a variable
Junior Talker

Posts: 2
Trades: 0
Hi.

I have a form with two input fields which is used to calculate the distance between two locations using Google Maps.
The form looks like this:

Code:
<form id="calculate" name="distance" action="#" onsubmit="showLocation(); return false;">
        <input type="text" name="address1" value="" size="30" />
        <input type="text" name="address2" value="" size="30" />
        <input type="submit" name="find" value="Go!" />
</form>
I would like to be able to fetch the locations from the input fields and put them into this link which gives you driving directions:
Code:
Code:
http://maps.google.com/maps?saddr={address1}&amp;daddr={address2}
The link is placed elsewhere on the same page. The values of the input fields are likely to be empty when the page loads.

Can someone help me with a way to get this solved?

Any help is appreciated. Thanks in advance.
meek is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-03-2009, 05:49 AM Re: How to get value from input field into link as a variable
Junior Talker

Posts: 2
Trades: 0
I solved with the following script:

Code:
<script type="text/javascript">

function showDirections(){
    window.open("http://maps.google.com/maps?saddr="+escape(document.getElementById("address1").value)+"&daddr="+escape(document.getElementById("address2").value));
}

</script>
And the link:
Code:
<a href="#" onclick="javascript:showDirections(); return false;" target="_blank">Click</a>
meek is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to get value from input field into link as a variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29901 seconds with 12 queries