Onchange下拉值查询响应.表格-使用php,mysql,ajax,jquery [英] Onchange dropdown values query resp. tables - with php , mysql , ajax , jquery
问题描述
主下拉列表:
<select name="sometest">
<option value="1"> A </option>
<option value="2"> B </option>
<option value="3"> C </option>
<option value="4"> D </option>
<option value="5"> E </option>
</select>
现在,当值1、2、3、4处于变化状态时,它应该从table_1获取其详细信息;而当值5处于变化状态时,则其详细信息来自另一个具有field(name,size,title)的表_2.
Now here When value 1 , 2, 3 , 4 is on-change it should get its details from table_1 and when Value 5 is on-change then its details come from another table_2 with field( name , size , title) .
请注意,table_1和table_2都具有相同的栏位字段名称.
Kindly note both table_1 and table_2 have same coloumn field name.
现在分别更改后.值,我得到另一个带有下拉列表.表查询.
now after onchange of resp. value i get another drop-down listing with resp. table query.
假设当我更改1或2或3或4的值时,它将查询具有字段名称,大小,标题的table_1并将其列出在resp下拉部分中.
Suppose when i on-change for 1 or 2 or 3 or 4 value , then it query table_1 with field name, size, title and list it under resp drop-down sections.
下拉列表:表_1中的1,2,3,4的变化值
在这里: table_1
<select name="name">
<option value="n1"> Apple </option>
<option value="n2"> Boy </option>
<option value="n3"> Cat </option>
</select>
<select name="size">
<option value="12"> 0-1 </option>
<option value="21"> 1-1 </option>
</select>
<select name="title">
<option value="1"> whatever </option>
<option value="2"> same whatever </option>
</select>
类似地,当从主"下拉列表中选择值5 时,它将从 table_2 中查询所有列字段,并将其分别列出.下拉
similarly when Value 5 is select from Main Drop-down , then it query all column field from table_2 and list it under resp. drop-down
推荐答案
用户ajax onchange选择框传递选择值
user ajax onchange select box pass the value of select
HTML
<select name="sometest" onchange="javascript:call_ajax_fun(this.value);">
<option value="1"> A </option>
<option value="2"> B </option>
<option value="3"> C </option>
<option value="4"> D </option>
<option value="5"> E </option>
</select>
JS Ajax函数
function call_ajax_fun(str)
{
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)
{
var result = xmlhttp.responseText;
if(xmlhttp.responseText!='')
{
document.getElementById('your_result_div_id').innerHTML =result ;
// put your result in your div
}
}
}
var url="get_result.php?pas_val="str;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
您的获取结果文件将如下所示
and your get result file will be as follows
get_result.php
<?php
if(isset($_REQUEST['pas_val']))
{
$pas_val = $_REQUEST['pas_val'];
if($pas_val<5)
{
$tbl = "table_1";
}
else
{
$tbl = "table_2";
}
// your table is in $tbl variable
// your your table here in your code
}
else
{
exit;
}
?>
这篇关于Onchange下拉值查询响应.表格-使用php,mysql,ajax,jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!