Solved

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

Posted on 2006-10-19
10
485 Views
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?
0
Comment
Question by:ly_uwo
  • 6
  • 3
10 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17770888
No need to use JavaScript. You can use <html:reset />

http://www.roseindia.net/struts/strutsHtmlTags.shtml
0
 

Author Comment

by:ly_uwo
ID: 17770945
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
 
LVL 16

Expert Comment

by:suprapto45
ID: 17770968
Okay,

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

Give me a sec....
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 16

Expert Comment

by:suprapto45
ID: 17771004
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
 

Author Comment

by:ly_uwo
ID: 17771464
Thanks. I will try it.
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17771540
Sure,

Sorry that I do not have Struts now. If you are in trouble again, please let me know.
0
 
LVL 16

Accepted Solution

by:
suprapto45 earned 200 total points
ID: 17771575
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
 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 50 total points
ID: 17777854
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
 

Author Comment

by:ly_uwo
ID: 17778573
Thank both of  you!
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17779128
Glad I could help :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
web service Rest Client creation 4 85
Coldfusion 10 - JSP File Not Found - 404 Error 5 92
instanceof  operator in java 26 91
by zero exception 10 39
One of the biggest threats facing all high-value targets are APT's.  These threats include sophisticated tactics that "often starts with mapping human organization and collecting intelligence on employees, who are nowadays a weaker link than network…
How do we balance the user experience (UX) with reasonable security measures? It can be done, if you keep these fundamentals in mind.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now