像這是我的表單的選擇框如何通過javascript傳遞選擇值?
<select name="cutid" onchange="findcustid(this.value)">
<option value="1001">cust 1</option>
<option value="1002">cust 2</option>
<option value="1003">cust 3</option>
</select>
現在我有這是通過這個Ajax代碼,並填寫一些選擇框
function findcustid(custid) {
var custid = custid;
}
function Inint_AJAX() {
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {} //IE
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {} //IE
try {
return new XMLHttpRequest();
} catch (e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById(src).innerHTML = req.responseText; //retuen value
}
}
};
req.open("GET", "podetfill.php?data=" + src + "&val=" + val + "&custid=" + custid); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
window.onLoad = dochange('proid', -1); // value in first dropdown
對上面這行代碼
req.open("GET", "podetfill.php?data="+src+"&val="+val+"&custid="+custid);
我已經添加了+"&custid="+custid
這個,但是它的通過值爲custid
,在podetfill.php
頁面上,並且獲得了e rror
Error: custid not defined
的CustID的本地範圍的給函數findcustid(上圖)增加下面。要使用它,你需要在函數之外聲明var custid。即全球。 – verisimilitude
你的代碼看起來好多了,現在它的格式正確 - 更容易閱讀 - 甚至可以幫助你解決你的問題...我的提示 - 總是縮進你的代碼([這裏有方便的HTML/JS美化](http: //jsbeautifier.org/)) – ManseUK