2010-05-18 3 views
1

Google Maps API를 사용하여 가격/거리 계산기를 구축 중이며 계산기의 정보를 별도의 페이지에있는 예약 양식으로 전달하려고합니다.별도의 페이지에서 한 양식에서 다른 양식으로 데이터 전달

내 첫 번째 양식에는 계산을 수행하는 버튼과 예약 양식에 관련 데이터를 제출하는 버튼이있는 2 개의 제출 버튼이 있습니다. 나는 두 번째 버튼을 작동 시키려고 노력 중이다.

API 계산이 끝나면 시작 값, 종료 값, 비용, 거리의 4 가지 값을 얻습니다. 두 번째 버튼을 클릭하여 From, To 및 Cost 값을 내 예약 양식으로 전달하려고합니다. 그러나 나는 그것을 할 수 있습니다. 나는 POST와 GET을 시도했지만, 나는 둘 다 뭔가 잘못된 일을했을 수도 있다고 생각한다. 어떤 도움을 주셔서 감사합니다. API 형태에 대한

코드 : 예약 양식에 대한

<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAwCUxKrPl8_9WadET5dc4KxTqOwVK5HCwTKtW27PjzpqojXnJORQ2kUsdCksByD4hzcGXiOxvn6C4cw&sensor=true"></script> 

<script type="text/javascript"> 

var geocoder = null; 
var location1 = null; 
var location2 = null; 
var gDir = null; 
var directions = null; 
var total = 0; 


function roundNumber(num, dec) { 
    var result = Math.floor(num*Math.pow(10 ,dec))/Math.pow(10,dec); 
    return result; 
} 

function from(form) { 
    address1 = form.start.options[form.start.selectedIndex].value; 
    form.address1.value=address1; 
    form.address1.focus(); 
} 

function to(form) { 
    address2=form.end.options[form.end.selectedIndex].value; 
    form.address2.value=address2; 
    form.address2.focus(); 
} 

function initialize() { 
    var map = new GMap2(document.getElementById("map_canvas")); 
    map.setCenter(new GLatLng(54.019066,-1.381531),9); 
    map.setMapType(G_NORMAL_MAP); 

    geocoder = new GClientGeocoder(); 
    gDir = new GDirections(map); 

    GEvent.addListener(gDir, "load", function() { 
     var drivingDistanceMiles = gDir.getDistance().meters/1609.344; 
     var drivingDistanceKilometers = gDir.getDistance().meters/1000; 
     var miles = drivingDistanceMiles.toFixed(0); 
     //var cost = (((miles - 1) * 1.9) + 3.6).toFixed(2); 
     var meters = gDir.getDistance().meters.toFixed(1); 

     if(miles < 70){    
      var cost = miles *1.75; 
     } 

     if(miles > 70){ 
      var cost = miles *1.2; 
     } 


     document.getElementById('from').innerHTML = '<strong>From: </strong>' + location1.address; 
     document.getElementById('to').innerHTML = '<strong>To: </strong>' + location2.address; 
     document.getElementById('cost').innerHTML = '<span class="fare"><strong>Estimated Taxi FARE:</strong>' + ' £' + cost.toFixed(2) + '</span>'; 
     document.getElementById('miles').innerHTML = '<strong>Distance: </strong>' + miles + ' Miles'; 
    }); 
} 

// start of possible values for address not recognized on google search 
// values for address1 
function showLocation() { 
    if (document.forms[0].address1.value == "heathrow" || document.forms[0].address1.value == "Heathrow" || document.forms[0].address1.value == "heathrow airport" || document.forms[0].address1.value == "Heathrow Airport" || document.forms[0].address1.value == "London Heathrow" || document.forms[0].address1.value =="london heathrow") { 
     (document.forms[0].address1.value = "Heathrow Airport"); 
    } 

    if (document.forms[0].address2.value == "heathrow" || document.forms[0].address2.value == "Heathrow" || document.forms[0].address2.value == "heathrow airport" || document.forms[0].address2.value == "Heathrow Airport" || document.forms[0].address2.value == "London Heathrow" || document.forms[0].address2.value =="london heathrow") { 
     (document.forms[0].address2.value = "Heathrow Airport"); 
    } 

    geocoder.getLocations(document.forms[0].address1.value + document.forms[0].uk.value || document.forms[0].start.value + document.forms[0].uk.value, function (response) { 
     if (!response || response.Status.code != 200) { 
      alert("Sorry, we were unable to find the first address"); 
     } else { 
      location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; 
      geocoder.getLocations(document.forms[0].address2.value + document.forms[0].uk.value, function (response) { 
       if (!response || response.Status.code != 200) { 
       alert("Sorry, we were unable to find the second address"); 
       } else { 
        location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; 
        gDir.load('from: ' + location1.address + ' to: ' + location2.address); 
       } 
      }); 
     } 
    }); 
} 
</script> 
<style> 
#quote { 
    font-family: Georgia, "Times New Roman", Times, serif; 
} 
</style> 

</head> 

<body style="background-color: rgb(255, 255, 255);" onUnload="GUnload()" onLoad="initialize()"> 

<div id="sidebar"> 

<!--MAPS--> 

<div id="calc_top"></div> 
<div id="calc_body"> 
<div id="calc_inside"> 

<span style="font-size: 16px; font-weight: bold;">Get A Quote Now</span> 

<p class="disclaimer">Fares can be calculated using either Area, Exact Address or Postcode, when entering address please 
include both road name and area i.e. <em>Harrogate Road, Ripon</em>. You can also select a pickup point and destination from the dropdown boxes. 
</p> 

<form onSubmit="showLocation(); return false;" action="#" id="booking_form"> 
<p> 
    <select onChange="from(this.form)" name="start"> 
    <option selected="selected">Select a Pickup Point</option> 
    <option value="Leeds Bradford Airport">Leeds Bradford Airport</option> 
    <option value="Manchester Airport">Manchester Airport</option> 
    <option value="Teesside International Airport">Teeside Airport</option> 
    <option value="Liverpool John Lennon Airport">Liverpool Airport</option> 
    <option value="East Midlands Airport">East Midlands Airport</option> 
    <option value="Heathrow International Airport">Heathrow Airport</option> 
    <option value="Gatwick Airport">Gatwick Airport</option> 
    <option value="Stanstead Airport">Stanstead Airport</option> 
    <option value="Luton International Airport">Luton Airport</option> 
    </select> 
</p> 
<p> 
    <input type="text" value="From" name="address1"><br> 
</p> 
<p> 
    <select onChange="to(this.form)" name="end"> 
    <option selected="selected">Select a Destination</option> 
    <option value="Leeds Bradford Airport">Leeds Bradford Airport</option> 
    <option value="Manchester Airport">Manchester Airport</option> 
    <option value="Teesside International Airport">Teeside Airport</option> 
    <option value="Liverpool John Lennon Airport">Liverpool Airport</option> 
    <option value="East Midlands Airport">East Midlands Airport</option> 
    <option value="Heathrow International Airport">Heathrow Airport</option> 
    <option value="Gatwick Airport">Gatwick Airport</option> 
    <option value="Stanstead Airport">Stanstead Airport</option> 
    <option value="Luton International Airport">Luton Airport</option> 
    </select> 
</p> 

<input type="text" value="To" name="address2"><br> 
<input type="hidden" value=" uk" name="uk"> 

<br> 
<input type="submit" value="Get Quote"> 
<input type="button" value="Reset" onClick="resetpage()"><br /><br /> 
<input type="submit" id="CBSubmit" value="Confirm and Book" action=""/> 

</p> 
</form> 

<p id="from"><strong>From:</strong></p> 
<p id="to"><strong>To:</strong></p> 
<p id="miles"><strong>Distance: </strong></p> 
<p id="cost"><span class="fare"><strong>Estimated Taxi FARE:</strong></span></p> 
<p id="results"></p> 

<div class="style4" style="width: 500px; height: 500px; position: relative; background-color: rgb(229, 227, 223);" id="map_canvas"></div> 

</div> 
</div> 

코드 : 사전에

<form method="post" action="contactengine.php" id="contact_form"> 
<p> 

<label for="Name" id="Name">Name:</label> 
<input type="text" name="Name" /> 

<label for="Email" id="Email">Email:</label> 
<input type="text" name="Email" /> 
<label for="tel" id="tel">Tel No:</label> 
<input type="text" name="tel" /><br /><br /> 
<label for="from" id="from">Pickup Point:</label> 
<input type="text" name="from" value="" /><br /><br /> 

<label for="to" id="to">Destination:</label> 
<input type="text" name="to" value=""/><br /> 
<label for="passengers" id="passengers">No. of passengers</label> 
<input type="text" name="passengers" /><br /><br /> 
<label for="quote" id="quote">Price of journey:</label> 
<input type="text" name="quote" value="" /><br /><br /> 
<label for="Message" id="Message">Any other info:</label> 
<textarea name="Message" rows="20" cols="40"></textarea> 
<br /> 

Are you an account holder?<br /> 
<label for="account" id="yes">Yes:</label> 
<input type="radio" class="radio" value="yes" name="account"> 

<label for="account" id="yes">No:</label> 
<input type="radio" class="radio" value="no" name="account"> 

</p> 
<small>Non-account holders will have to pay a £5 booking fee when confirming their booking</small> 
<input type="submit" name="submit" value="Submit" class="submit-button" /> 
</p> 

</form> 

감사

답변

1

당신은

<form onSubmit="return false;" action="booking_form.php" id="booking_form"> 

후 제출 사용할 수 있습니다

<input type="submit" value="Get Quote" onclick="return showLocation();"> 
<input type="button" value="Reset" onClick="resetpage()"> 
<input type="submit" id="CBSubmit" value="Confirm and Book" onclick="this.form.submit();"> 

은 그것을위한 간단하고 효율적인

+0

감사의 - 거의 그것의 예약 양식에 값을 전달하지 제외. 정보 양식을 첫 번째 양식으로 가져 오기 위해 예약 양식에 다음 코드를 넣었습니다 : Micanio

+0

정렬 됨 - 도움 주셔서 감사합니다. – Micanio

2

는 통과 쓰고 싶은 수량의 각각에 숨겨진 필드를 추가 자신의 양식을 제출하기 전에 값을

document.getElementById('hidden_field_id').value = calculated_value 
(210)
관련 문제