Search code examples
javascripthtmlformspostreload

How to reload a page without resubmitting the form using javascript?


I am working on a small stock management project. After adding an item into the database, the reset button stops working. I was able to reset everything except the html-5 date attribute and checkbox using javascript as such

$form.find('input:text, input:password, input:file, select,textarea').val('');           
$form.find('input:radio, input:checkbox, input:dropdown').removeAttr('checked').removeAttr('selected');

So, i'm trying to reload the page altogether using
location.reload(true);
But, now it prompts asking to resubmit the form. What could be the solution to this? Is there any other way to reset the form?

Sorry, i'm new to programming. I'll appreciate your help.


Solution

  • In the server side script, after adding the item, redirect to the same page rather than directly displaying it. pseudo code of the server side script:

    Rather than:

    if(additem() == success)
    {
       display_form()
    }
    

    do this:

    if(additem() == success)
    {
       redirect('/your/form_url')
    }