• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 520
  • Last Modified:

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

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?
0
ly_uwo
Asked:
ly_uwo
  • 6
  • 3
2 Solutions
 
suprapto45Commented:
No need to use JavaScript. You can use <html:reset />

http://www.roseindia.net/struts/strutsHtmlTags.shtml
0
 
ly_uwoAuthor Commented:
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.
 
0
 
suprapto45Commented:
Okay,

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

Give me a sec....
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
suprapto45Commented:
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.
0
 
ly_uwoAuthor Commented:
Thanks. I will try it.
0
 
suprapto45Commented:
Sure,

Sorry that I do not have Struts now. If you are in trouble again, please let me know.
0
 
suprapto45Commented:
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 = '';
    }
</script>

<%-- name may be useful here --%>
<html:text property="test" size="10" name="test" />
<html:button property="submit" value="Submit" onclick="return resetForm();" />
0
 
jaggernatCommented:
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.
0
 
ly_uwoAuthor Commented:
Thank both of  you!
0
 
suprapto45Commented:
Glad I could help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now