当key =在php输入时禁用表单方法发布和输入

时间:2014-04-03 20:51:50

标签: javascript php keypress enter

您好,我的代码中有很多函数,比如自动完成。

当我按enter时,我的功能开始并完成。

但现在我添加了一些其他按钮,当我按下enter时,我的页面会刷新,我不希望这样。

我在本网站和Google上尝试了这些示例。但它们不起作用。

onsubmit="return false";

onkeypress="refuserToucheEntree(event);
function refuserToucheEntree(event)
{
   // Compatibilité IE / Firefox
   if(!event && window.event)
   {
     event = window.event;
   }

   // IE
   if(event.keyCode == 13)
   {
      event.returnValue = false;
      event.cancelBubble = true;
   }

   // DOM
   if(event.which == 13)
   {
      event.preventDefault();
      event.stopPropagation();
   }
}

感谢您的帮助!

**编辑:这是我的代码**

<script type="text/javascript" src="script/calcul.js"></script>


        <!-- fonction ajouter une rangé -->
<script type="text/javascript">


 $(function () {
      $("select").tooltip({
          content: function () {
              return $(this).val();
          }
      });
  });


var rowNum = 0;
function addRow(frm) {
    rowNum ++;
    var row = '<p id="rowNum'+rowNum+'"> Item name: <input type="text" name="name[]" value="'+frm.add_name.value+'"> Item client[]: <input type="text" name="client1[]" size="4" value="'+frm.client1.value+'"><input type="button" value="Remove" onclick="removeRow('+rowNum+');" > </p>';
    jQuery('#itemRows').append(row);
    frm.client1.value = '';
    frm.add_name.value = '';
var monInput = document.getElementById('add_name');
var monElement = document.createElement('div');
monInput.parent.insertBefore(monElement, monInput.nextElementSibling);
}

function removeRow(rnum) {
    jQuery('#rowNum'+rnum).remove();
}
</script>



    <?php
        // Connect to the DB
        $link = mysqli_connect("localhost","root","","testlp") or die("Error " . mysqli_error($link));

        // store in the DB 
        if(!empty($_POST['ok'])) 
        {  
        // first delete the records marked for deletion. Why? Because we don't want to process them in the code below
        if( !empty($_POST['delete_ids']) and is_array($_POST['delete_ids'])) 
            foreach($_POST['delete_ids'] as $id)
            {
                $sql = "DELETE FROM recherche WHERE id=$id";
                $link->query($sql);
            }
    }

    // adding new recherche
    if(!empty($_POST['name'])) 
    {
        foreach($_POST['name'] as $name)
        {
        //escape special characters from inputed "name" to prevent SQL injection.

            $sql = "INSERT INTO recherche (name) VALUES ('".mysqli_real_escape_string($link,$name)."')";
            $link->query($sql);
        }
    } 

    // select existing recherche here
    $sql="SELECT * FROM recherche ORDER BY id";
    $result = $link->query($sql);
    include("Log.php"); 


// include("dynamic-form-fields.html.php"); 


//chercher pour la colone tache
        $pdo = new PDO('mysql:host=10.82.182.165;dbname=ohmega', 'zabbix', 'ohmega');
        #Set Error Mode to ERRMODE_EXCEPTION.
        $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
        $stmt = $pdo->prepare('Select * from taches');
        $stmt->execute();


?>
    Bienvenue <?php echo($usrUserName);?>   

</br>
<table>
    <!-- en tete du tableau -->
    <tr>
        <td>
            Date/Jour
        </td>

        <td>
            # de Projet
        </td>

        <td>
            Client
        </td>

        <td>
            Courte description du projet
        </td>

        <td>
            Description de la tâche effectué
        </td>

        <td>
            Lieu
        </td>

        <td>
            Tache
        </td>
        <td>
            Total
        </td>

        <tr>
        <tr>
            <td>
    <!--------------------------------- JOURNÉE DE DIMANCHE --------------------------->
                <b>Dimanche</b> </br><?php echo $date1 ?>

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

                <span id="numpro" >
                 <form method="post" action="" onsubmit="return false; "onkeypress="refuserToucheEntree(event);">

                        <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ée -->
                <input onclick="addRow(this.form);" type="button" value="+" /> 

                </form>
                    <!-- fonction doubler la rangée 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>
                <p><input type="submit" name="ok" value="Terminé"></p>
                </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ébut 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"  name="tempsd" size="30" id="temps1"class= "temps"   min= "0" max="24" value="0"  />   

                </span>
            </td>


            </br>
            <!-----------------------------------LUNDI----------------------------------------------------->        
            </tr>
            <tr>
                <td>
                    <b>Lundi</b> </br><?php echo $date2 ?>
                </td>
                <td>
                    </br>
                    <input size="10" type="text" id="proj1" name="proj1"onkeypress="return handleEnter2(event, this, 'task');"/>

                </td>
                <td>
                    </br>
                    <input type="text" name="client2" class = "client" size="12" id ="client2" disabled />
                </td>
                <td>
                    </br>

                    <input type="text" name="projDesc2" size="30" class "desc" id ="projDesc2"disabled />
                </td>
                <td>
                    </br>
                    <textarea rows="1" cols="20" name="taskDesc1"> </textarea>
                </td>
                <td>
                    </br>
                    <input type="text" name="lieu1" size="10">
                </td>
                <td>
                </br>

<!-- début section cobobox 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();

                            //echo '<option value="'.$row['tacName'].'">'.$row['tacId'].'</option>'."\n";
                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->    

                </td>   

            <!-- calculter le temps pour le lundi -->       


                        <td>
                        </br>
                    <span id="calculTemps1">
                        <input type="number" id="temps1" class="temps"  name="tempsl" size="10" min="0" max="24" value="0" />
                    </span>
                </td>   


        </tr>
            <!-----------------------------------MARDI----------------------------------------------------->        
        <tr>
            <td>
                <b>Mardi</b> </br><?php echo $date3 ?>
                    </td>

            <td>
                <input size="10" type="text" id="proj2" name="proj2"onkeypress="return handleEnter3(event, this, 'task');"/>

            </td>
            <td>
                    <input type="text" name="client3" class = "client" size="12" id ="client3" disabled />

            </td>
            <td>
            <input type="text" name="projDesc3" size="30" class "desc" id ="projDesc3"disabled />
            </td>
            <td>
                <textarea rows="1" cols="20" name="taskDesc1"> </textarea>
            </td>
            <td>
                <input type="text" name="lieu1" size="10">
            </td>


                </br>

                <td>
                    <!-- début section cobobox 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();

                            //echo '<option value="'.$row['tacName'].'">'.$row['tacId'].'</option>'."\n";
                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->    
                </td>   


            <td>
            <span id="calculTemps2">
                <input id="temps3" type="number" class= "temps"  name="tempsma" size="2" min="0" max="24" value="0"/></br>
                </span>
            </td>
        </tr>
            <!-----------------------------------Mercredi-----------------------------------------------------> 
        <tr>
            <td>
                <b>Mercredi</b> </br><?php echo $date4 ?>

                    </td>

            <td>
                <input size="10" type="text" id="proj3" name="proj3"onkeypress="return handleEnter4(event, this, 'task');"/>

            </td>
            <td>
                        <input type="text" name="client4" class = "client" size="12" id ="client4" disabled />
            </td>
            <td>    
            <input type="text" name="projDesc4" size="30" class "desc" id ="projDesc4"disabled />
            </td>
            <td>
                <textarea rows="1" cols="20" name="taskDesc1" /> </textarea>
            </td>
            <td>
                <input type="text" name="lieu1" size="10" />
            </td>

                <td>
                    <!-- début section cobobox 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();

                            //echo '<option value="'.$row['tacName'].'">'.$row['tacId'].'</option>'."\n";
                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->    
                </td>   


            <td>

                <span id="calculTemps3">

                <input   class= "temps" type="number" name="tempsme" size="2" min="0" max="24" value="0" />
            </span>



            </td>
        </tr>
        <!-----------------------------------Jeudi----------------------------------------------------->    
        <tr>
            <td>
                <b>Jeudi</b> </br><?php echo $date5 ?>
            </td>
            <td>
                    <input size="10" type="text" id="proj4" name="proj4"onkeypress="return handleEnter5(event, this, 'task');"/>
            </td>
            <td>
                    <input type="text" name="client5" class = "client" size="12" id ="client5" disabled />
            </td>
            <td>
                <input type="text" name="projDesc5" size="30" class "desc" id ="projDes5"disabled />
            </td>
            <td>
                <textarea rows="1" cols="20" name="taskDesc1"> </textarea>
            </td>
            <td>
                <input type="text" name="lieu1" size="10">
            </td>


                <td>
                    <!-- début section cobobox 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();

                            //echo '<option value="'.$row['tacName'].'">'.$row['tacId'].'</option>'."\n";
                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->    

                </td>   

            <td>


            <span id="calculTemps4">
                <input id="temps4" type="number" class= "temps"  name="tempsje" size="2" min="0" max="24" value="0"/></br>
                </span>


            </td>
        </tr>
        <!-----------------------------------Vendredi-----------------------------------------------------> 
        <tr>
            <td>
                <b>Vendredi</b> </br><?php echo $date6 ?>
                    </td>

            <td>
                    <input size="10" type="text" id="proj5" name="proj5"onkeypress="return handleEnter6(event, this, 'task');"/>
            </td>
            <td>
                <input type="text" name="client6" class = "client" size="12" id ="client6" disabled />
            </td>
            <td>
                <input type="text" name="projDes6" size="30" class "desc" id ="projDes6"disabled />
            </td>
            <td>
                <textarea rows="1" cols="20" name="taskDesc1"/> </textarea>
            </td>
            <td>
                <input type="text" name="lieu1" size="10"/>
            </td>
            <td>
                    <!-- début section cobobox 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();

                            //echo '<option value="'.$row['tacName'].'">'.$row['tacId'].'</option>'."\n";
                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->    

                </td>   


            <td>
            <span id="calculTemps5">
                <input class= "temps"  type="number" name="tempsv" size="2" min="0" max="24" value="0" /></br>
                </span>
            </td>
        </tr>
        <!-----------------------------------Samedi----------------------------------------------------->   
        <tr>
            <td>
                <b>Samedi</b> </br><?php echo $date7 ?>

                    </td>

            <td>
                        <input size="10" type="text" id="proj6" name="proj6"onkeypress="return handleEnter7(event, this, 'task');"/>
            </td>
            <td>
                        <input type="text" name="client7" class = "client" size="12" id ="client7" disabled />
            </td>
            <td>
                    <input type="text" name="projDes7" size="30" class "desc" id ="projDes7"disabled />
            </td>
            <td>
                <textarea rows="1" cols="20" name="taskDesc1"> </textarea>
            </td>
            <td>
                <input type="text" name="lieu1" size="10">
            </td>


                <td>
                    <!-- début section cobobox 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();

                            //echo '<option value="'.$row['tacName'].'">'.$row['tacId'].'</option>'."\n";
                        }
                    ?>
</select>
</label>
<!-- Fin section cobobox tache avec tool tip -->    
                </td>   


            <td>
            <span id="calculTemps6">

                <input  class= "temps" id ="temps" type="number" name="tempss" size="2" min="0" max="24" value="0"></br>

                </span>

            </td>

        </tr>
        <!--    HEURES TOTALES-->
        <tr>

            <td>
                <b>total des heures </b> </br>
            </td>

            <TD ALIGN="right"  class="hide">

            </td>

            <TD ALIGN="right"  class="hide">

            </td>

            <TD ALIGN="right"  class="hide">

            </td>

            <TD ALIGN="right"  class="hide">

            </td>

            <TD ALIGN="right"  class="hide">

            </td>

            <TD ALIGN="right"  class="hide">

            </td>
            <td>
                <input id="result" readonly="readonly" type="text" value="0" size = "10" />




    <!-- <input type="text" id="total" name="total" readonly="readonly" size="5;&quot;">



    -->



                <p><input type="submit" name="ok" value="Terminé" onsubmit="return false;" onkeypress="refuserToucheEntree(event);"></p> 
            </td>

            </td>

        </tr>

    </table>

0 个答案:

没有答案