i need to show different values only in drop down list.drop down list selection based result cal in ajax and display the related data show below in the drop down list.
How to pass the string value to ajax in this script.
Anyone pls guide me
<!doctype html>
<html class="no-js" lang="en">
<head>
<script>
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=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="row">
<div class="large-12 columns">
<h1></h1>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<!--Main Tab Start-->
<?php
$res=mysql_query("select DISTINCT tag,id from password");
if($res === false )
{
die(mysql_error());
}
?>
<form action="" method="post">
<select name="tagg" onchange="showUser(this.value)">
<option value="">Select Accounts</option>
<?php
while($row=mysql_fetch_array($res))
{
$dess=$row['tag'];
$id=$row['id'];
?>
<option value="<?php echo $id;?>"><?php echo $dess; ?></option>
<?php
}
?>
</select>
</form>
<div id="txtHint"><b>Person info will be listed here.</b></div>
<!--Main Tab Ent-->
</div>
</div>
</body>
</html>
Getuser.php
<?php
$q = intval($_GET['q']);
$result=mysql_query("select * from password WHERE id = '".$q."'");
if($result === false )
{
die(mysql_error());
}
while($row=mysql_fetch_array($result))
{
$desss=$row['tag'];
}
$res=mysql_query("select * from password WHERE tag = '".$desss."'");
if($res === false )
{
die(mysql_error());
}
?>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>username</th>
<th>Password</th>
<th>Description</th>
<th>Link</th>
</tr>
</thead>
<?php
while($row=mysql_fetch_array($res))
{
$id=$row['id'];
$name=$row['name'];
$url=$row['url'];
$uname=$row['username'];
$pass=$row['password'];
$tag=$row['tag'];
$des=$row['description'];
?>
<tbody>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $uname; ?></td>
<td><span data-tooltip aria-haspopup="true" class="has-tip" title="<?php echo $pass; ?>">View</span></td>
<td><span data-tooltip aria-haspopup="true" class="has-tip" title="<?php echo $des; ?>">Description</span></td>
<td><a href="<?php echo $url; ?>" title="<?php echo $name; ?>" target="_blank">Link</a></td>
</tr>
</tbody>
<?php
}
?>
</table>