SALAM
man mikham yek drop down select menu ba ajax benevisam ke maghadire dropdown ro az server begire va vaghti ke yeki az maghadir ro entekhab mikonam bar asase select option value un option value ro be javascript function befrestam ke in function 1 php page ro tu server side farakhani mikone va 1 table ro ke havie information marbut be selected dropdown value bud ro namayesh mide.
here is my code:
<?php
$dbservertype='mysql';
$servername='localhost';
// username and password to log onto db server
$dbusername='root';
$dbpassword='';
// name of database
$dbname='wba';
////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
connecttodb($servername,$dbname,$dbusername,$dbpas sword);
function connecttodb($servername,$dbname,$dbuser,$dbpasswor d)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////// End of connecting to database ////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Edit Guard Information</title>
<!-- <SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='editguard2.php?cat=' + val ;
}
</script> -->
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
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)
{
document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
}
}
xmlhttp.open("GET","editguard2-ck.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
@$cat=$_GET['cat']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";
exit;
}
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT g_name,g_id FROM guard order by g_name");
///////////// End of query for first list box////////////
//echo "<form method=post name=f1 action='editguard2-ck.php'>";
echo "<form >";
echo "<select name='cat' onchange=\"showUser(this.value)\"><option value=''>Select Guard</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['g_id']==@$cat){echo "<option selected value='$noticia2[g_id]'>$noticia2[g_name]</option>"."<BR>";}
else{echo "<option value='$noticia2[g_id]'>$noticia2[g_name]</option>";}
}
echo "</select>";
////////////////// This will end the first drop down list ///////////
echo "</form>";
?>
</html>
I want to pass $noticia2[g_id]from php to javascript function .