I have two input fields, the values are coming through database. I want one user change the value of one input field, the second one change automatically based upon the value of first. I am using ajax, so far i have following code:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
function ajaxfunction(parent)
{
$.ajax({
type: 'GET',
url: 'process.php?parent=' + parent,
success: function(data) {
$("#sub").html(data);
}
});
}
</script>
</head>
<body>
<select onchange="ajaxfunction(this.value)">
<?php
$q= mysql_query("select * from tab1");
while ($row= mysql_fetch_array($q)){
$name= $row['name'];
echo '
<option> '.$name.' </option>
';
}
?>
</select>
<select id="sub"></select>
</select>
</body>
</html>
and my process.php file is:
<?php
$result = mysql_query("SELECT * FROM `contents` WHERE `parent` = " . mysql_real_escape_string($_GET["parent"]));
while(($data = mysql_fetch_array($result)) !== false)
echo '<option value="', $data['id'],'">', $data['name'],'</option>'
?>
where i am doing wrong, I am even not getting the value of (parent). anyone help me please.
Regards