We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


In struts jsp page, how to use javascript to reset all the fields in the form

ly_uwo asked
Medium Priority
Last Modified: 2010-04-01
Hi, how to use javascript to reset all the fields in the form? I have three selection list and one text field. I am using <html:form> tag. How can I use javascript to clear them?
Watch Question

No need to use JavaScript. You can use <html:reset />



looks good. However, the selections can't be changed. They are defined by struts code like <logic:equal> <option value=** selected > <logic:equal> <logic:notequal> <option value=** > </logic:notEqual>.

Any other ideas? Or somehow similar examples? Thanks.

If that is not possible then you have to use JavaScript.

Give me a sec....
Can you try to add the <html:button> that has the onClick attribute to execute some JavaScript? Because I am not using Struts at the moment.


Thanks. I will try it.

Sorry that I do not have Struts now. If you are in trouble again, please let me know.
Just a thing that I normally do. I am not sure whether it works or not.

<script language="JavaScript" type="text/JavaScript">    
    function resetForm() {
         alert('coming here');
         // resetting here but not sure how to get the
        document.getElementById("test").value = '';

<%-- name may be useful here --%>
<html:text property="test" size="10" name="test" />
<html:button property="submit" value="Submit" onclick="return resetForm();" />

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
suprapto's code should help. Although , if you want to reset a few selected fields without reseting the entire page, you can do that by getting the value of each field from the form-bean and reseting them in javascript.


Thank both of  you!
Glad I could help :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.