2013-05-30 27 views
0

由於我relativly新的使用PHP和JavaScript我就遇到了這個問題,而試圖在一個URL添加多個變量在頁面URL使用JavaScript

我用下面的腳本添加多個變量:

<script> 
function refresh() { 
var PCWDE = document.getElementById("PC"); 
var NMWDE = document.getElementById("naam"); 
var VNMWDE = document.getElementById("voornaam"); 
var ONDWDE = document.getElementById("onderneming"); 
var BTWWDE = document.getElementById("btwnummer"); 
var LNDWDE = document.getElementById("land"); 


     this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value "&nm=" + NMWDE.value "&vnm=" + VNMWDE.value "&ond=" + ONDWDE.value "&btw=" + BTWWDE.value "&lnd=" + LNDWDE.value; 

} 
</script>  

這是beeing激活槽下面的HTML代碼:

<?php 
    $pc = $_GET['PCS']; 
    echo '<input type="text" name="pc" id="PC" onblur="refresh()" value="'.$pc.'">' 
    ?> 

爲使用這個網站代碼的主要原因是,我需要執行沒有子查詢即使在頁面刷新的時候,仍然能夠保持文本框的值。上面的html代碼被多次使用,使用不同的ID。

,同時試圖做到這一點我所面臨的問題是,當只增加1個變量的URL,像這樣我的代碼只能:

this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value; 

否則這是行不通的。 'onblur'事件無法工作,或腳本無法運行。

有沒有一種方法可以以類似的方式將多個變量添加到URL中?

回答

1

你忘了加號。這是一個語法錯誤,如果您打開錯誤控制檯,您應該看到錯誤消息。 (在Firefox你按Ctrl-Shift-J)

Shoule是:

this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value + "&nm=" + NMWDE.value + "&vnm=" + VNMWDE.value + "&ond=" + ONDWDE.value + "&btw=" + BTWWDE.value + "&lnd=" + LNDWDE.value; 
+0

它的偉大工程,謝謝!並感謝您的提示! – mhaegens