我有一個輸入的文字,我想,當我需要的是價值,並傳遞它的URL參數點擊一個按鈕,這是我到目前爲止的代碼:通過輸入文本參數
<div id="landmark-1" data-landmark-id="1">
<form name ="data">
<label>enter your name :</label>
<input type= "text" placeholder="ID" name="ID" value="" style="width:206px;" />
<input type="submit" value="Suivant" onclick="showUser(this.form)" >
</form>
</div>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
,這是我的javascript代碼:
<script>
function showUser(frm)
{
var str = frm.ID.value;
if (str==""){
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://localhost/filename/page.php?q="+str,true);
xmlhttp.send();
}
</script>
,但是當我輸入一個名稱,它只是增加:在當前頁面的URL ID =名字!它不會在我想要的網址發送參數..
嘗試:var str = frm.elements ['ID'] .value; – jeff
同樣的事情,它通過當前頁面的url:?ID = name – neustre
而不是'「http://localhost/filename/page.php?q =」+ str'嘗試'「http:// localhost /filename/page.php「+ str' – collapsar