View Full Version : Passing input value from one page to another

07-15-2011, 08:37 PM
I'm fairly new at this. I'm trying to build a store locator and trying to figure out how to pass an input value from one page to another page. User would input their zipcode or address in a form on one page and the map and locations would be called on another page using the input.

I'm using ehound store locator platform (sample - here -> http://www.ehoundplatform.com/api/1.0/demos/freehound-google.html)

The map/locator script is this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Store Locator Demo using FreeHound and Google Maps V.3</title>
<style type="text/css">
#map_canvas {
height: 400px;
margin-bottom: 10px;
.addressBox {
<script type="text/javascript" src="http://www.ehoundplatform.com/api/1.0/proximity.js?key=xz396aw1qe432q1"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&region=AU"></script>
<script type="text/javascript">
var geocoder;
var map;
var bounds;
var markersArray = [];
var infoWindow;
var mapCenterLat = '-28.1594';
var mapCenterLon = '135.6456';

function initialize() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 4,
center: new google.maps.LatLng(mapCenterLat, mapCenterLon),
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

//initialise single info window to show only one at a time
infoWindow = new google.maps.InfoWindow();

//improve usability by centering map around search point on zoom in/out
google.maps.event.addListener(map, 'zoom_changed', function() {
if(mapCenterLat && mapCenterLon) {
setTimeout('centerMap(mapCenterLat, mapCenterLon)', 300);

function addMarkerOverlay(location, title, infoBox, image) {
var marker = new google.maps.Marker({
position: location,
map: map,
icon: image

google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map, marker);


function deleteOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray.length = 0;

function searchAroundMe() {

bounds = new google.maps.LatLngBounds();

var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {

//custom marker to mark initial search location
var image = new google.maps.MarkerImage('search_location.png',
// This marker is 32 pixels wide by 32 pixels tall.
new google.maps.Size(32, 32),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the center of the red circle at 16,16.
new google.maps.Point(16, 16)

addMarkerOverlay(results[0].geometry.location, 'search spot', 'search initiated from here', image);

var searchLatitude = results[0].geometry.location.lat();
var searchLongitude = results[0].geometry.location.lng();

mapCenterLat = searchLatitude;
mapCenterLon = searchLongitude;

freeHound = new FreeHound( 'showLocs' );
search = new FH_Search();
search.count = 10; //number of locations to be returned in the result set
search.max_distance = 0; //distance limit for proximity search in km, 0 for unlimited
//search from a specific point using latitude and longitude of that point
search.point = new FH_Location( new FH_LatLon( searchLatitude,searchLongitude ) );

//search.filters = new Array();
//search.filters.push( new FH_SearchFilter('cat_id', 'eq', '177') );

search.create_log = false;
freeHound.proximitySearch( search );
} else {
alert("Geocode was not successful for the following reason: " + status);

function showLocs(response){
if ( response.error_code ) {

if ( response.record_set ) {
//show results in a table
var resultsTable = '<table border="1" cellspacing="0" cellpadding="3" summary="">';
resultsTable += '<tr>';
resultsTable += '<td>#<\/td>';
resultsTable += '<td>Street Address<\/td>';
resultsTable += '<td>Town/Suburb/City<\/td>';
resultsTable += '<td>Postal Code<\/td>';
resultsTable += '<td>State/Province<\/td>';
resultsTable += '<td>Distance<\/td>';
resultsTable += '<td>Longitude<\/td>';
resultsTable += '<td>Latitude<\/td>';
resultsTable += '<\/tr>';

for (var record_count = 0, rl = response.record_set.length; record_count < rl; record_count++ ) {
var record = response.record_set[record_count];
var title = record.details.location_name;
var infoBoxContent = '<strong>Location #'+(record_count+1).toString()+'<\/strong>';
infoBoxContent += '<br \/>'+record.address.street_address+'<br \/>'+record.address.town + ', ' + record.address.postal_code +'<br \/>';
infoBoxContent += 'Distance: '+record.distance.km+'km<br \/>';
addMarkerOverlay(new google.maps.LatLng(record.latitude, record.longitude), title, infoBoxContent, null);

if (record_count < 6) {
bounds.extend(new google.maps.LatLng(record.latitude, record.longitude));

resultsTable += '<tr>';
resultsTable += '<td>'+(record_count+1).toString()+'<\/td>';
resultsTable += '<td>'+record.address.street_address+'<\/td>';
resultsTable += '<td>'+record.address.town+'<\/td>';
resultsTable += '<td>'+record.address.postal_code+'<\/td>';
resultsTable += '<td>'+record.address.state+'<\/td>';
resultsTable += '<td>'+record.distance.km+'KM<\/td>';
resultsTable += '<td>'+record.longitude+'<\/td>';
resultsTable += '<td>'+record.latitude+'<\/td>';
resultsTable += '<\/tr>';


resultsTable += '<\/table>';

var resultSet = document.getElementById('resultSet');
resultSet.innerHTML = resultsTable;

function centerMap(lat,lon) {
var centrePoint = new google.maps.LatLng(lat,lon);
<body onload="initialize()">
<div class="addressBox">

<form action="" onsubmit="searchAroundMe(); return false;">
<input id="address" type="textbox" value="">
<input type="submit" name="search" value="Address Search">
<div id="map_canvas"></div>
<div id="resultSet"></div>

and the form itself would be on another page. Trying to pull the address input over. This obviously doesn't work

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Store Locator</title>

<form action="ehound.html" method="post">
<input id="address" name="address" type="textbox">
<input type="submit" name="search" value="Address Search">


I've looked around on passing inputs via php and such, but this script seems to call on javascript as well and I'm having trouble implementing anything that works. Any help would be greatly appreciated.

Old Pedant
07-16-2011, 12:15 AM
You can't use method="post" unless you use server-side code to process the posted data.

You *can* use method="get", which puts the data into a querystring in the URL. JavaScript *can* parse the querystring to get information.

location.search contains the querystring of the URL that invoked the page, including the leading question mark.

That is, if the URL was "ehound.html?address=123%20Elm%20St.&search=Address%20Search" then location.search will hold "?address=123%20Elm%20St.&search=Address%20Search". So you just have to parse that to find the name/value pairs you are interested in.


var qsVars = [ ];
if ( location.search.length > 2 )
var pairs = location.search.substring(1).split("&");
for ( var p = 0; p < pairs.length; ++p )
var pair = pairs[p].split("=");
qsVars[ pair[0] ] = decodeURIComponent( pair[1] );

Once you run that code, then you can ask for query string variables by name by doing (example):

var address = qsVars["address"];

07-18-2011, 03:13 PM
I understand what this is trying to do - getting rid of all the extraneous characters that are generated and then when you make that the var, it is the exact address input from the user.

I'm just not sure where the code goes in the script. I can't get it to work anywhere I put it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum