duanrang3357 2014-11-23 02:28 采纳率: 0%
浏览 14
已采纳

如何根据选择输入类型填充文本输入类型? [关闭]

I am new to web development. I want to know how to populate text input type based on select drop down. Say I am selecting branch and I want its employee number automatically in text box. Can it be done using AJAX? If yes how? I want employee number from MySQL database. Plus I want to display its arrival time in other text input from same MySQL table. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • duanqiechui2378 2014-11-23 04:16
    关注

    Yes, this surely can be done with JQuery & Ajax. So your code will look something like

    $(document).on("change","#dropDownSelector", function(){
    
    var changedVal = $("#dropDownSelector").val();
    
    $.ajax({
                type: 'POST',
                url: 'actionUrl', //logic for getting the data based on dropdown valur from db
                data: { 
                    "value": changedVal,
    
                },
                beforeSend:function (){
                    //Do something before request is sent like showing loading image
                },
                success:function (data){
                    //Success . Use the data and show it on ui
                },
              error: function(xhr, textStatus, errorThrown){
                // failed request; give feedback to user
    
              },
              complete:function (){
                    //Do something after request is complete.   
              }
            });
    

    You still need to create the url and action for that based on the server side language and database you are working on. But overall your javascript code should follow this.

    Hope this be of some help.

    Happy Learning :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算