在点击选择选项时从数据库填充的Jquery文本字段 [英] Jquery text field populating from database on clicking select option

查看:140
本文介绍了在点击选择选项时从数据库填充的Jquery文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择选项框,如果我点击选择选项,下面的其他两个文本应该加载数据库中的数据,基于选择选项id值。如何做到这一点
php和jquery或cakephp和jquery
提前感谢

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 value.How to do this with php and jquery or cakephp and jquery thanks in advance

推荐答案


  1. 捕获change事件选择框

  2. 将信息的ajax帖子发送到.php页面(将读取值,检索并回显数据库中的数据)

  3. ajax post将定义一个回调函数,它将在成功时调用(当php完成回传数据时),这将填充两个字段。

因此

$(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);
                                          }
                          )

               });
});

并且在你的php中,你需要读取在getJSON调用中发送的selectVal url参数,

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"}

这篇关于在点击选择选项时从数据库填充的Jquery文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆