Sunday, 18 August 2013

Feed to select from mysql db through Ajax

Feed to select from mysql db through Ajax

I have the following Code
if($('#b_ID').length==1){
$('#gen, #dob').change(function(){
$.ajax({
type: "POST",
url: "<?=APP_PATH?>ajax/json.class.php",
data: {
gen: $('#gen').val()
,dob: $('#dob').val()
},
}).done(function( msg ) {
var wcs = $.parseJSON(msg);
console.log(wcs);
$('#b_ID').html('');
$('#b_ID').append('<option
value="">'+'<?=_('[Select]')?>'+'</option>');
$.each(wcs, function(){
$wc=$(this);
//check for original value
var selected =
$('#orig_ID').val()==$wc[0].ID_w?'
selected="selected"':'';
$('#b_ID').append('<option '+selected+'
value="'+$wc[0].ID_w+'">'+$wc[0].w_d+'</option>');
})
})
})
}
The above code is working perfect, if the form is loaded from other
previous form. For example,
form1.php contains two fields dob text input select option
After we insert dob and select from option, when I save and then I load
the second form which contains the select option that depends on those two
inputs. For this purpose it works OK.
but what I need is I have all the elements on the form, all three fields,
including one input and two select, so according to the first input of dob
and the second select, I want to fill the third selection.
How could I change the above code to be able to work?

No comments:

Post a Comment