选择后自动完成操作

时间:2014-04-09 13:51:22

标签: javascript php jquery html autocomplete

您好,我有一个自动填充代码,在我输入第一个字母后会显示一个单词。如果我输入例如ca,则会建议catterpillarcat等等。
当我点击任何结果时,我的其他输入都已完成。点击我的选择后,我的其他输入可以立即完成吗?

这是我的身体和输入:

<!--------------------------------- JOURNé DE DIMANCHE --------------------------->
                <b>Dimanche</b> </br><?php echo $date1 ?>

            </td>
            <!-- num de projet du dimanche -->
            <td>

                <span id="numpro" >
                 <form method="post" action="" onsubmit="return false;">

                        <input type="text" id="name" name="add_name"onkeypress="return handleEnter(event, this, 'task');"/> 

                        <?php
                        if($result!=false && mysqli_num_rows($result)>0)
                            {
                                while($product = mysqli_fetch_array($result)): ?>
                                    <p id="oldRow<?=$product['id']?>">     <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" />  </p>
                                <?php   endwhile;
                            }
                                ?>
                </span>         
                <!-- Bouton ajouter une rangé-->
                <input onclick="addRow(this.form);" type="button" value="+" /> 
                </form>


            <!-- fonction doubler la rangé du dimanche -->  

                <div >
                <form method="post"  >
                    <div id="itemRows">
                        <?php

                            if($result!=false && mysqli_num_rows($result)>0)
                            {
                                while($product = mysqli_fetch_array($result)): ?>
                                    <p id="oldRow<?=$product['id']?>">  <input type="text" name="client1<?=$product['id']?>" size="4" value="<?=$product['client1']?>" />   <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" />  </p>
                                <?php endwhile;
                            }
                                ?>
                    </div>

                </form>
                </div>

            </td>


            <!-- client du dimanche -->
            <td>
                <span id="proclient">   

                <input type="text" name="client1" size="12" class = "client1"  id ="client1" disabled />    



                </span>
            </td>
            <!-- description du projet de dimanche -->
            <td>
                <span id="prodesc">
                    <input type="text" name="desc1" size="30" id ="desc1" class "desc" disabled />
                </span>
            </td>
            <!-- ddescription de la tache du dimanche -->
            <td>
                <span id="protache">
                    <textarea rows="1" cols="20" name="taskDesc1" id ="task1" class "task"> </textarea>
                </span>
            </td>
            <!-- lieu pour dimanche -->
            <td>
                <span id="prolieu">
                    <input type="text" name="prolieu1" size="10" id ="lieu1" class "lieu">
                </span> 
            </td>   


            <!-- tache  -->     
            <td>
                <span id="tache">
                <!--    <input type="text"  name="tache" size="30" id="tache"class= "tache"  />  -->    

                <!-- dꣵt section combobox tache avec tool tip -->                   
                    <label title="Select your state"> <select title="Select your state" id="state" name="state">
                    <?php

                        $stmt->execute();
                        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                            echo ' <option title="';
                            echo $row['tacName'];
                            echo '">';
                            echo $row['tacId'];
                            echo '</option>'."\n";
                         $task = array();


                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->        

                </span>
            </td>

            <!-- calculter le temps pour le diamnche -->        
            <td>
                <span id="calculTemps">
                <input type="number" id="input1"  class="temps"  name="tempsdi" size="10" min="0" max="24" value="0"/><br/>



                </span>
            </td>


            </br>

这是我的功能

//------------------AUTO COMPLETE NUMʒO DE PROJET---------------------- 
                $(document).ready(function(){

            //-------AUTO COMPLETE DIMANCHE PROJET-----
                    $("#name").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                    });
            //-------AUTO COMPLETE LUNDI PROJET-----
                       $("#proj1").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                    });
            //-------AUTO COMPLETE MARDI PROJET-----    
                     $("#proj2").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                        });
            //-------AUTO COMPLETE MERCREDI PROJET----- 
                    $("#proj3").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                        });
            //-------AUTO COMPLETE JEUDI PROJET-----    
                    $("#proj4").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                        });
            //-------AUTO COMPLETE VENDREDI PROJET----- 
                    $("#proj5").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                        }); 
            //-------AUTO COMPLETE VENDREDI PROJET----- 
                    $("#proj6").autocomplete({
                        source:'getautocomplete.php',
                        minLength:1
                        }); 

                });
                //------------------COMPLETE addrow DESC DIMANCHE----------------------
                function handleEnter(e, obj, field){

                    if (e.keyCode == 13 || e.which == 13){
                        if (window.XMLHttpRequest)
                          {// code for IE7+, Firefox, Chrome, Opera, Safari
                            xmlhttp=new XMLHttpRequest();
                          }
                        else
                          {// code for IE6, IE5
                            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                          }
                        xmlhttp.onreadystatechange=function()
                          {
                            if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                {
                                    tempArrayInJS = JSON.parse(xmlhttp.responseText); 
                                    $("#client1[]").val( tempArrayInJS[0]['cliName']);

                                }
                          }
                        xmlhttp.open("GET","completeclient.php?q="+obj.value,true);
                        xmlhttp.send();

                    }
                    //Enter was pressed, handle it here

                    }
//------------------COMPLETE CLIENT DESC DIMANCHE----------------------
                function handleEnter(e, obj, field){

                    if (e.keyCode == 13 || e.which == 13){
                        if (window.XMLHttpRequest)
                          {// code for IE7+, Firefox, Chrome, Opera, Safari
                            xmlhttp=new XMLHttpRequest();
                          }
                        else
                          {// code for IE6, IE5
                            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                          }
                        xmlhttp.onreadystatechange=function()
                          {
                            if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                {
                                    tempArrayInJS = JSON.parse(xmlhttp.responseText); 
                                    $("#client1").val( tempArrayInJS[0]['cliName']);
                                    $("#desc1").val( tempArrayInJS[0]['proDescription']);
                                }
                          }
                        xmlhttp.open("GET","completeclient.php?q="+obj.value,true);
                        xmlhttp.send();

                    }
                    //Enter was pressed, handle it here

                    }

0 个答案:

没有答案