简体   繁体   English

jQuery .change多个文本框并选择逐行检索数据

[英]jquery .change multiple textbox and select retrieve data from row to row

I have a code that will display select and textbox depending on the count of the loop. 我有一个代码,将根据循环数显示select和textbox。 The select dropdown will display currencies on acronym format if selected example USD the textbox will display "US Dollars". 如果选择的示例是美元,则选择下拉列表将以首字母缩写格式显示货币。文本框将显示“美元”。 on the second loop if I select JPY it will display Japan Yen on the textbox on the second row and so on. 在第二个循环中,如果选择“日元”,它将在第二行的文本框中显示“日元”,依此类推。 Is this possible on jquery? 在jQuery上这可能吗?

Here is my code 这是我的代码

<script>
         $(document).ready(function(){
            $('#acr').change(function(){
                //get json + this.value get corresponding value on db
                //retrieve data
            });
         });
    </script>

<?php
   foreach($data as $d) {
?>
   <select name = "acr" id = "acr">
    //Records from db
   </select>
   <input type = "text" readonly value = ""> <br>

<?
   }
??

Yes. 是。 But first please give a name attribute to your textbox and assume its id is 'longName'. 但是首先请给您的文本框指定名称属性,并假设其ID为'longName'。 You may have two options: 您可能有两个选择:

option 1: Save the currencies short name/Long name in select. 选项1:在选择中保存货币简称/姓氏。 JPY code: 日元代码:

        $('#acr').change(function(){
          $('#longName').val($(this).val());   
        });

option 2: 选项2:

$('#acr').change(function(){
          var sel = $(this);   
          $.ajax({
              url: "your url",
               type: "POST",
               data: 'data='+sel.val(),
               dataType:'json',
                  success: function(data) {
                          //Do what ever you want. Data holds the response from server
                   },
              error: function() {
                          //Error occured, handle it    
           }
       });
        });

Read more on ajax here 这里阅读更多关于ajax的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM