清除PHP回显值输入字段

时间:2018-05-23 11:31:47

标签: php html

我有一个表单,通过php的echo函数显示表中点击的值。回声逻辑如下:

     //reading input
     if(isset($_POST['add'])){
        $scrid=$_POST['sc'];
        $desc=mysqli_real_escape_string($_POST['desc']);
        $cb=mysqli_real_escape_string($_POST['created']);
        $version=mysqli_real_escape_string($_POST['version']);
        if($scrid !=0){
            if(empty($desc)){$result="Description cannot be Empty";}
            elseif(empty($cb)){$result="Created By cannot be Empty";}
            elseif(empty($version)){$result="Version cannot be Empty";}
            else{
                echo $t."empty";
                $sql="INSERT INTO testmaster(ScreenID,Description,createdBy,version) VALUES('$scrid','$desc','$cb','$version');";
                if(mysqli_query($link,$sql)){                         
                         header('Location: testmaster.php');
               }else{
                    echo "Query failed";
                   }
            }
        }
    }
                      //passing table values,,,,, works perfectly fine...
                    if(mysqli_num_rows($sol)>0){
                   while($row=mysqli_fetch_assoc($sol)){
                            echo"<tr>";

                            echo"<td><a href=testmaster.php?testid=".$row['tid'].">".$row['Description']."</a></td>";
                            echo"<td>".$row['createdBy']."</td>";
                            echo"<td>".$row['version']."</td>";
                            echo "</tr>";
                    }
                }      
                }
        if(isset($_GET['testid'])){
        $t=$_GET['testid'];
        $query="SELECT * FROM testmaster WHERE tid='$t';";
        if($sol=mysqli_query($link,$query)){
            $modif=mysqli_fetch_assoc($sol);
            $d=$modif['Description'];
            $c=$modif['createdBy'];
            $v=$modif['version'];
            $sc=$modif['ScreenID'];

        }

//These are the input fields



echo'<td><textarea name="desc" class="form-rounded" cols=50 rows=2 
    placeholder="Description">'.$d;
    echo'</textarea></td>';
    echo'<td><input type="text" name="created" class="form-control" 
    placeholder="Created By" value='.$c.'>';
    echo'</td>';

//cancel


echo "<input type='reset' class='btn button2' name='cancel' id='cancel' value='Cancel' style='height:12px; text-align:center; margin-left:10px;' >" ; 

取消按钮和Clear text field value in JQuery中指定的javascript代码均无效。

我猜是因为我回应了它。  任何人都可以帮助我吗? 在此先感谢.... :)

P.S。所有输入字段和取消按钮都在...

1 个答案:

答案 0 :(得分:-1)

如果您在代码中包含了JQuery,那么您可以这样做:

  1. clear-onclick (或其他名称)类添加到您想要为空的所有字段
  2. onclick 处理程序添加到按钮
  3. 表格代码

     echo'<td><textarea name="desc" class="form-rounded clear-onclick" cols=50 rows=2 
    placeholder="Description">'.$d;
    echo'</textarea></td>';
    echo'<td><input type="text" name="created" class="form-control clear-onclick" 
    placeholder="Created By" value='.$c.'>';
    echo'</td>';
    

    按钮代码

     <input type='reset' class='btn button2' name='cancel' id='cancel' onclick="javascript: $('.clear-onclick').val(null)" value='Cancel' style='height:12px; text-align:center; margin-left:10px;' >
    

    您可以按如下方式包含jQuery:

    echo '<script src="https://code.jquery.com/jquery-3.3.1.js"></script>';