Jump to content

Filter Data


june_c21

Recommended Posts

hi,

i got problem when i click on the option value in 1st drop down, the 2nd drop down menu didn't appear. Anything wrong in my php code ?

 

 

html code

<html>
<head>
<title>My Page</title>
<script type="text/javascript">

// SharpAJAX initialization

// Create AJAX object based on browser
if (navigator.appName == "Microsoft Internet Explorer") {
	sharpajax = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	sharpajax = new XMLHttpRequest();
			}

// Initialize
sharpajax.abort();

</script>
<script type="text/javascript">

// My Function

function filter(value) {
     
	// Resets state
	sharpajax.abort();

	// Send command
	sharpajax.open("GET","filter.php?filter="+value);

	// Create input trapping function
	sharpajax.onreadystatechange=function() {
		if (sharpajax.readyState == 4) {
			eval(sharpajax.responseText);
		}
	}

	// Send output
	sharpajax.send("");
}

</script>
<script type="text/javascript">
function createDropdown(container, id) {
	document.getElementById(container).innerHTML = ''+
	'<select name="'+id+'" id="'+id+'">'+
	'</select>';
}
function addDropdownItem(container, value, caption) {
	document.getElementById(container).innerHTML = ''+
	document.getElementById(container).innerHTML +
	'<option value="'+value+'">'+caption+'</option>';
}
</script>
</head>
<body>
<div id="filters_1">
<select name="filter1" id="filter1" onChange="javascript:filter(this.value);">
	<option value="name">Name</option>
	<option value="birthdate">Birthdate</option>
</select>
</div>
<div id="filters_2"></div>
</body>
</html>


 

 

php code

<?php

$myfilter = $_GET['filter'];

// SQL query statements goes here


$host = 'localhost';
$user = 'root';
$password = '';
$dbase = 'drawing';

$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);


$filters_2 = $_POST['title'];



$query = "SELECT title FROM drawings ";
  $result1 = mysql_query($query, $dblink);
  while($myrow1 = mysql_fetch_row($result1))
    {
printf("createDropdown('filters_2','filter_2');");
printf("addDropdownItem('filter_2','filtervalue','
filtercaption'");
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.