
Originally Posted by
Pullo
Yay
Just for my personal interest, could you please post your final code (similar to what you posted in the first post, but obviously the working version).
Thanks!
Hi pullo,
Here is now the working code,but please correct me if i am wrong.
Code:
$(function(){
$.ajax
({
type: "POST",
data: "id="+myid,
url: "members.php",
success: function(r)
{
var id = r.empid;
$('#emp').val(r.empname);
mydropdown(id);
}
});
});
function mydropdown(id){
$.ajax({
type: 'post',
data: 'id='+id,
url: 'toselectdropdown.php',
success: function(data){
$.each(data, function(key, val) {
if(key==clscode)
$('#my-new-select').append($('<option></option>').val(key).html(val).attr('selected','selected'));
else
$('#my-new-select').append($('<option></option>').val(key).html(val));
});
}
});
}
}
toselectdropdown.php
Code:
if(isset($_POST['id'])){
$con = mysql_query("select * from employee");
if(!$con)
die("Unable to load".mysql_error());
$data=array();
while($row = mysql_fetch_array($con)){
$empdata[$row['emp_id']]=$row['emp_address'];
}
}
header('Content-type: application/json');
echo json_encode($empdata);
}
Bookmarks