开发者

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


  1. Capture the change event of the select box
  2. do an ajax post of the info to a .php page (which will read the value, retrieve and echo the data from the db)
  3. 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"}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜