0

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.

James Black
  • 41,583
  • 10
  • 86
  • 166
chaosifier
  • 2,666
  • 25
  • 39
  • possible duplicate of [How can I refresh a page with jQuery?](http://stackoverflow.com/questions/5404839/how-can-i-refresh-a-page-with-jquery) – Evan Davis Jun 19 '14 at 17:08
  • The normal approach is after you receive the submitted for you make a small redirect in the server side language of choice, when you reload the page it reloads the page you redirected to, not the page the form was submitted to. – scragar Jun 19 '14 at 17:08
  • Once they submit then reset doesn't make sense, as the database has been updated, unless you create a new row for each update. Once they submit, clear all the values, or just reload the page fresh keeping their session. – James Black Jun 19 '14 at 17:28
  • 1
    `checked` is a property. Sample: `.prop('checked', false);` Reference: [`.prop()`](http://api.jquery.com/prop/) – War10ck Jun 19 '14 at 17:28
  • Redirecting to the same page solved the problem. Thank you all. – chaosifier Jul 25 '14 at 16:31

1 Answers1

0

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')
}
Prasanth
  • 43
  • 2
  • 7