自动填充文本框取决于下拉值 [英] Auto fill text box depending on Drop Down value

查看:133
本文介绍了自动填充文本框取决于下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我想澄清一下如何解决这个问题。我遇到过很多文章,可以根据drop中的选择设置文本框的值下面菜单使用jQuery和Ajax.My问题是当我尝试做同样的事情时,取决于5个下拉菜单中的选择。我有Id值存储在数据库中,应该用来填充文本框。可以任何人都指导如何通过多次下拉来解决这个问题。到目前为止,这是我的代码。

This might be a stupid question but I would like to have a clarification on how to go about this.I have come across quite a few articles that let to set the values of a text box depending on the choices made in a drop down menu using jQuery and Ajax.My issue is when I'm trying to do the same depending on the choices made in 5 drop down menus.I have the Id values stored in the database which should be used to populate the text box.Can anyone guide on how to go about this issue with multiple drop downs. This is my code so far.

    <?php
     $sql1="SELECT Schlungen  FROM schulung as s"; 
     $result=mysql_query($sql1); 
     echo "<p align='left'> <strong>Schulung 1</strong> <select name='Schlungen1'>           <option value default></option>";
     while ($row = mysql_fetch_array($result)) 
     {
     echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . "   </option>";
      }
      echo "</select>";
      ?>

      <?php
      error_reporting(0);
      //Drop Down for Schulung 2
      $sql2="SELECT Schlungen  FROM schulung as s"; 
      $result=mysql_query($sql2); 
      echo "<p align='left'> <strong>Schulung 2</strong> <select name='Schlungen2'>  <option value default></option>";
      while ($row = mysql_fetch_array($result)) 
      {
      echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
       }
      echo "</select>";
      ?>


      <?php
      error_reporting(0);
      //Drop Down for Schulung 3 
      $sql3="SELECT Schlungen  FROM schulung as s"; 
      $result=mysql_query($sql3); 
      echo "<p align='left'> <strong>Schulung 3</strong> <select name='Schlungen3'> <option value default></option>";
      while ($row = mysql_fetch_array($result)) 
      {
      echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . "</option>";
       }
      echo "</select>";
      ?>

      <?php
      error_reporting(0);
      //Drop Down for Schulung 4 
      $sql4="SELECT Schlungen  FROM schulung as s"; 
      $result=mysql_query($sql4); 
      echo "<p align='left'> <strong>Schulung 4</strong> <select name='Schlungen4'><option value default></option>";
      while ($row = mysql_fetch_array($result)) 
      {
      echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
       }
      echo "</select>";
      ?>

      <?php
      error_reporting(0);
      //Drop Down for Schulung 5  
      $sql5="SELECT Schlungen  FROM schulung as s"; 
      $result=mysql_query($sql5); 
      echo "<p align='left'> <strong>Schulung 5</strong> <select name='Schlungen5'><option value default></option>";
      while ($row = mysql_fetch_array($result)) 
      {
      echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
      }
      echo "</select>";
      ?>   
      <p align="left"><strong>Access_level </strong> 
      <input type="text" name="a_level" disabled="disabled">
      </p>


推荐答案

要实现自动完成,您可以创建一个选择字段在html文件中,在keyup事件上调用javascript函数并使用jQuery调用你的php文件

For achieving auto completion,you can create a select field in html file,call a javascript function on keyup event and use jQuery for calling your php file

<html>
<head>
    <script>
        $('.autosuggest').keyup(function(){
         $.post("<your file.php>",{any data you need},function(data){
          //echo the data
        //echo "<option value='" . $row['Schlungen'] . "'>" . //$row['Schlungen'] ."   </option>";
        $('.result').html(data)

});
        });
        $('.result option').click(function(){
            var rValue = $(this).text();
            $('.autosuggest').attr('value',rValue);        
            $('.result').html('');
        });

    </script>
</head>
<body>
    <input type='text' class='autosuggest'/>
    <select class='result'>
    </select>
</body>
</html>

这篇关于自动填充文本框取决于下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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