Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

javascript - Auto fill text box depending on Drop Down value

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>

    
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...