Hey,
I have a simple page where I can select a client, then once I chose that autopopulate to the projects that belong to the client. I am using PHP/MySQL to pull the results.
I took at a look at this: http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ but I think that starts with both fields on the page. I tried to rework the code but didn't come out that well.
Any ideas on any type of reference?
Thanks,
Ryan
UPDATE 2: Here is my jQuery is this all I need or do I need the other sections, this code doesnt work as is.
Thanks for your help!
Ryan
var client_id = $('#c_id').val();
$.getJSON("../inc/get-projects.php", {id: client_id}, function(data){
projects = $('#p_id');
projects.empty();
$.each(data, function() {
var option = $('<option/>').attr('value', this.id).text(this.name);
projects.append(option);
});
});
PHP:
<?php
include "config.inc.php";
$sth = mysql_query(
sprintf(
"SELECT c_id,p_id,p_title FROM projects WHERE c_id = %s",
mysql_real_escape_string($_GET['id'])
)
);
$projects = array();
while($r = mysql_fetch_assoc($sth)) {
$projects[] = array('id' => $r['p_id'], 'name' => $r['p_title']);
}
print json_encode($projects);
exit;
?>