javascript - How to clear the pre-post values of form fields after submit, and fill the form again with the blank fields


This is my website where I have applied a script to clear the form fields values after submit. Basically when you book the appointment for the first time and done. You again come back on the same page for another appointment then you will see that all the fields of form already filled. So I do not want this happens on the live website. I have used a script to clear the fields but it is working on firebug console but not worked on the live website. Is there anything wrong what I did earlier, Below is my script that I have used and committed to the server.

<script type="text/javascript">
jQuery(document).ready(function (){

Please help how we can clear the form fields for the second time to book an appointment.

Many thanks!




Possibly caused by browser autocomplete? Try addingautocomplete="off" to yourform tag.




<!DOCTYPE html>
    <title>your page</title>
    <form action="">
        <input type="text" id="sngl_txt">
        <textarea id="mlt_txt"></textarea>
        <select id="selection">
          <option value="">no selection (default)</option>
          <option value="1">option 1</option>
          <!-- and so on -->

        <button type="button" id="rst_btn">reset form</button>

<script type="text/javascript" src=""></script>
<script type="text/javascript">

$(document).on('ready', function(){

  // prepare with sample values
  $('form').find('#sngl_txt').val('sample text');
  $('form').find('#mlt_txt').val('Lorem ipsum ....");

  var reset = function(){
    $('form').find('input, textarea, select').val('');

  $('form').find('#rst_btn').on('click', reset);

  // or
  // $('form').find('#rst_btn').on('click', function(){
  //   reset();
  // });
  // if you don't want to use the reset funtion as listener



i know in this sample a simple button type="reset works too", but i often have to work with customized controls and i had to set the value to an empty string by hand.

what you can try is$('form').reset() and not$('.form-horizontal').reset(), the effect will be the same a reset

People are also looking for solutions to the problem: php - Remove shipping fee in cart page in woocommerce 3.0?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.