|
 |
|
ผมอยากทราบวิธีส่งค่าให้ ajax จาก listmenu 2อันครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<script language="JavaScript">
var HttPRequest = false;
function list_names(user) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'query_user.php';
var pmeters = 'user='+user;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
User :
<select name="userlist" id="userlist" onChange="list_names(this.value);">
<?php
echo "<option value=\"all\" >All</option>";
$sql = mysql_query("SELECT user FROM account");
while($objResult = mysql_fetch_row($sql))
{
echo "<option value=\"$objResult[0]\" >$objResult[0]</option>";
}
?>
</select>
Tool :
<select name="typelist" id="typelist">
<option value="all" >All</option>
<option value="discoveringtool" >Motif Discovering Tool</option>
<option value="assesment1" >Assesment Tool 1</option>
<option value="assesment2" >Assesment Tool 2</option>
</select>
ผมที่ list/menu อยู่2อันคือ user กับ tools
ซึ่งใช้สำหรับ filter ค่าที่จะแสดงออกมาจาก database
ซึ่งถ้าผมใส่user ไปมันจะแสดงผลออกมาเฉพาะ user นั้นๆ
แต่ถ้าผมจะ ใส่ tools เพิ่มไปด้วยมันเรียงตาม user และ tools ด้วย
ผมจะใส่parameter เข้าไปใน ajax ได้ยังไงครับ
Tag : PHP, MySQL, HTML/CSS, Ajax

|
|
 |
 |
 |
 |
Date :
2011-01-26 12:16:27 |
By :
NewSkins |
View :
1373 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีใครทราบเลยหรอครับ
|
 |
 |
 |
 |
Date :
2011-01-26 17:35:40 |
By :
NewSkins |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมมือใหม่นะครับ ไม่รู้ว่าทำไปได้แล้วหรือยัง
ลอง ดึงค่าของ tool ไปด้วยเลย (แต่มันต้องเลือกtool ก่อนนี่สิ เพราะมัน onchange ที่ user)
ด้วย var pmeters = 'user='+user+'&tool='+encodeURI( document.getElementById("typelist").value)
แล้วค่อยไปกำหนดเงื่อนไขการ select ใน ไฟล์'query_user.php'
มีรอผู้รู้มาแนะนำอีกที
|
 |
 |
 |
 |
Date :
2012-02-06 10:54:34 |
By :
diawcpe |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
var pmeters = 'user='+user;
ตรงนี้ทำไมมี code แค่นี้เองหล่ะคับ
|
ประวัติการแก้ไข 2012-02-06 15:31:55
 |
 |
 |
 |
Date :
2012-02-06 15:31:09 |
By :
newMeMber (มือใหม่เหมือนกัน) |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
var url = 'AjaxPHPRegister2.php';
var pmeters = "tUsername=" + encodeURI( document.getElementById("txtUsername").value) +
"&tPassword=" + encodeURI( document.getElementById("txtPassword").value ) +
"&tName=" + encodeURI( document.getElementById("txtName").value ) +
"&tEmail=" + encodeURI( document.getElementById("txtEmail").value );
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
|
 |
 |
 |
 |
Date :
2012-02-07 09:04:58 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|