Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reset the form to Null or Reload the page using reset even after a submit

 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

This is the scenario:

I have two button - Submit and Reset

Submit is used for validation and after validation is passed it passes it to another form to enter into database.

Basically the reset works fine if I use it before using the submit button in the form. For instance,if on submit there is some error as the values have not passed a validation. There is a error pop up message shown and the values are retained in the field and Now if I use reset , all the values of the field do not go back to null.

I am new with form validation. I checked online and it said that reset will not clear if we have used submit and we need to use javascript to do it.

So I made reset into a button which onclick event calls the reset() function and clears the form but I am sure that the code is not right as it is not working, I tired putting a alert message in my function to reassue that the function is being called but I think it is not.



I am not sure if its the best way to do it.

I want the whole form to refresh/ reload every time reset is clicked and all the fields to have no values.

Thanks for the help in advance.
Sumant
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not found the html reset function very useful because of the problems you have mentioned. If you just want to clear all the fields in the form, I'd suggest you just use an html:button for your clear button and have it call a JavaScript function that sets each field to blank. Example:
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Merrill,

I used the same code earlier with button, but unable to clear the form fields.

I will tell you once again:

Step 1: I entered some text in the form fields and i clicked on submit button, then its validated form fields, failed and returned back to the same page with old values.
Step 2:When I clicked on the reset button, once again the action is calling without reset to null in the form, this shouldn't be happened.

I did the same thing what you suggested. but wasn't working properly.
I used Struts 1...

Could you pls another way to suggest me


thanks,
Sumant K
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method that I showed you will work if done propertly. Please post your JSP and any error messages you got, and we'll help you debug it if you like. One thing you may not be aware of: Don't name your function reset() as this is a pre-defined JavaScript function for an HTML form. Name it something else.

If you're still looking for a different alternative, you may want to consider using the <html:cancel> tag. This causes a submit of the form without validation. You would then use the isCancelled() method of the Action class to determine whether the cancel button had been pressed and then clear all the ActionForm properties. Be aware that if you're using Struts 1.2.9 or above, you must specify cancellable="true" in the Action mapping for this action in the struts-config.xml file.
[ March 19, 2008: Message edited by: Merrill Higginson ]
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill,

Oh..! My code is working, i can able to refresh my form fields

Thank you very much on your valuable suggestion.

I'm sorry about my last reply without proper testing i replied you.

Now its working..!

Since 1 week I was struggling with this code.

thanks,
Sumant K
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic