2014-01-29 32 views
0

的第一個PHP文件:如何在另一個(第二個)php文件中使用onsubmit函數?

<form onsubmit="showAddress(this.address.value); return false;" method="post" > 
    <h2>Enter Address</h2> 
     <input type="number" class=" typeahead large_inputbox" name="address" maxlength="6"/> 
     <input type="submit" value="Submit" class="submit" /> 
</form> 

第二php文件:

function showAddress(address) { 
var geocoder = new google.maps.Geocoder(); 
geocoder.geocode({ 'address': address}, function(results, status) { 
if (status == google.maps.GeocoderStatus.OK) { 
    map.setCenter(results[0].geometry.location); 
    map.setMapTypeId(google.maps.MapTypeId.HYBRID); 
    if (map.getZoom() < 16){map.setZoom(16);}else{} 
    marker.setPosition(results[0].geometry.location); 
    posset = 1; 
    computepos(results[0].geometry.location); 
} else { 
    alert("Geocode was not successful for the following reason: " + status); 
} 

}); 
} 

如何使用的onsubmit功能在另一個(第二個)PHP文件?

+0

你爲什麼要使用'的onsubmit()'在第二檔 – krishna

+0

因爲showAddress參數值在Google地圖上選取地址..所以我使用showAddress函數.. – Logz

回答

0

可以包括裏面的第一個PHP文件第二php文件

0

showAddress實際上是一個JavaScript函數,因此它在當前的HTML頁面來定義,或包含的JavaScript文件之一。

可以包括包含在HTML文件中的函數的php文件:

<script src="php_with_function.php" /> 

或者在PHP中:

<script> 
<?php require "php_with_function.php"; ?> 
</script> 
+0

請使用<?php而不是

+0

編輯答案,謝謝 – Tzach

+0

t haks你Tzach ...問題沒有解決.. – Logz

相關問題