0
我有一個窗體有兩個輸入文本框:移動和擴展,我想提供一個由jQuery自動填充以填充另一個文本框,如標題,部門等,我可以這樣做這樣的如何根據輸入的文本框ID做mysql查詢?
index.php
//form start
<input type="text" name="mobile" id="mobile" onchange = "mobilecheck();" size="10" maxlength="30" value="" />
<input type="text" name="extension" id="extension" onchange = "extensioncheck();" size="10" maxlength="30" value="" />
//form end
//auto populate work well so I skip those codes
//function start
var url = "check.php?q=";
function mobilecheck() {
var idValue = document.getElementById("mobile").value;
var myRandom=parseInt(Math.random()*99999999); // cache buster
if (idValue=="") return;
http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function extensioncheck() {
var idValue = document.getElementById("extension").value;
//the other are same with mobilecheck() so skip it
//function end
使用相同的PHP文件做MySQL查詢 check.php
//query start
$result = mysql_query("SELECT * FROM mycontact WHERE (mobile like '$q') or (extension like '$q'));
//query end
它工作得很好,但我不知道是否有更好的方法來做到這一點像開關兩種功能於一體結合起來。
有什麼建議嗎?謝謝。
感謝@ user1705877使用內存緩存,它的作品! – eagle
@ user1705877,如何在發送查詢時爲移動設備添加前綴?對於移動「12345678」,添加前綴「001」,然後發送查詢「001-12345678」 – eagle
通過「document.getElementById(type).value」獲取移動值「 嘗試更改爲: var idValue ='prefix'+ document.getElementById(type).value; 如果只發生移動,請爲type = mobile添加if語句。 – Warren