Jquery text field populating from database on clicking select option
I'am having a select option box,if i click on the select option,two other text below it should be loaded with data from database,based on select option id va开发者_如何学JAVAlue.How to do this with php and jquery or cakephp and jquery thanks in advance
- Capture the change event of the select box
- do an ajax post of the info to a .php page (which will read the value, retrieve and echo the data from the db)
- the ajax post will define a callback function that will be called on success (when the php is done echoing the data), which will populate the two fields..
so
$(document).ready(function(){
$('your_select_box_selector').change(function(){
$.getJSON( 'your_php_page.php',
{selectVal: $(this).val()},
function(data){
$('text1_selector').val(data.text1);
$('text2_selector').val(data.text2);
}
)
});
});
and in your php you will need to read the selectVal url parameter we sent in getJSON call, and output something like this
{"text1": "text to go in the first text box", "text2": "text for the second text box"}
精彩评论