سلام
من در مثال بالا می خواهم پس از اینکه کاربر combobox ها را onchange کرد در textbox متنی را براساس آنچه که در combobox انتخاب شده از بانک بخواند و در textbox نمایش دهد.
کد را به صورت زیر تغییر دادم ولی چون خیلی به جاوااسکریپت و اینا آشنایی ندارم نمیدونم درست نوشتم یا نه. کار نمیکنه.
یه تابع result2 را در رویداد onchange کمبو باکس دوم قرار دادم. لطفا اگر امکانش هست تابع result2 و فایل result2.php را ببینید.
index.php
[PHP]<html>
<head>
<?php
include("../site/connect.php");
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled</title>
<script type="text/javascript">
function result(value){
if(value.length==0){
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)
{//alert(xmlhttp.responseText);
document.getElementById("result").innerHTML=xmlhtt p.responseText;
}
}
xmlhttp.open("GET","result.php?id="+value,true);
xmlhttp.send(null);
}
</script>
<script type="text/javascript">
function result2(){
var select1=document.getElementById('select1').selecte dIndex;
var select2=document.getElementById('select2').selecte dIndex;
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)
{ alert(xmlhttp.responseText);
document.getElementById("rade").value=xmlhttp.resp onseText;
}
}
xmlhttp.open("GET","result2.php?id1="+select1+"&&i d2="+select2,true);
xmlhttp.send(null);
}
</script>
</head>
<body >
<div align="center" >
<?php
$q="select * from typebook";
$res=mysql_query($q);
?>
<select name="number_query" onchange="result(this.value);" id="select1">
<?php
for($i=0;$i<mysql_num_rows($res);$i++){
$f=mysql_fetch_array($res);?>
<option value="<?php echo $f['idtype'];?>"><?php echo $f['type'];?></option>
<?php }?>
</select>
</div>
<br>
<div align="center" id="result">
<select id="select2" onChange="result2();">
<option></option>
</select>
</div>
<input name="rade" type="text" id="rade">
</body>
</html>
[/PHP]
result2.php
[PHP]<?php
include("../site/connect.php");
$id=$_GET["id1"];
$id2=$_GET["id2"];
$q="select * from typebook join subtype using(idtype) where idtype=$id and idsubtype=$id2";
$res=mysql_query($q);$f=mysql_fetch_array($res);
print $f['rade'].$f['zirrade'];
?>[/PHP]