php - Clear html text fields -


i have html form submitting , retrieves data mysql database 2 buttons, "save/submit" , "new/reset" fetch data correctly mysql database when click on new/reset button new contact entry couldn't clear forms text fields. html , php codes under:

<?php //database connection file. include'connect.php'; $sql = mysql_query("select * contact_list id='1'"); while($result = mysql_fetch_assoc($sql)){    $fname = $result['fname'];    $lname = $result['lname'];    $email = $result['email'];    $contact = $result['contact']; }  if(isset($_post['fname'])&&isset($_post['lname'])&&isset($_post['email'])&& isset($_post['contact'])){    $fname = $_post['fname'];    $lname = $_post['lname'];    $email = $_post['email'];    $contact = $_post['contact'];  if($sql = mysql_query("insert contact_list values ('', '$fname', '$lname', '$email', '$contact')")){    echo'contact save successfully.'; }else{    echo'contact not save.'; } } ?> <html> <form action="sample.php" method="post">    first name:<input type="text" name="fname" value="<?php if(isset($fname))    {echo $fname;}?>">    last name:<input type="text" name="lname" value="<?php if(isset($lname))    {echo $lname;}?>">    email:<input type="text" name="email" value="<?php if(isset($email))    {echo $email;}?>">    contact:<input type="text" name="contact" value="<?php if(isset($contact))    {echo $contact;}?>"> //clean fields of forms new entry.    <input type="reset" value="new"> //save or submit form data mysql database    <input type="submit" value="save"> </form> </html> 

you can using jquery

<html> <head> <script type="text/javascript"> $(document).ready(function() {     $("#btnreset").click(function(){        $("#fname").val("");        $("#lname").val("");        $("#email").val("");        $("#contact").val("");     });  });  </script> </head> <form action="sample.php" method="post">    first name:<input type="text" name="fname" value="<?php if(isset($fname))    {echo $fname;}?>" id="fname">    last name:<input type="text" name="lname" value="<?php if(isset($lname))    {echo $lname;}?>" id="lname">    email:<input type="text" name="email" value="<?php if(isset($email))    {echo $email;}?>" id="email">    contact:<input type="text" name="contact" value="<?php if(isset($contact))    {echo $contact;}?>" id="contact"> //clean fields of forms new entry.    <input type="reset" value="new" id="btnreset"> //save or submit form data mysql database    <input type="submit" value="save" id="btnsave"> </form> </html> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -