Solved

clear text boxes on web page when hit 'back' button

Posted on 2009-07-04
3
325 Views
Last Modified: 2012-05-07
I have two jsp files. The first jsp accept user input in form and then it calls the second jsp using Form action. And in the second JSP, it passes those two inputs to my Java Bean program, and then accept the output again from java bean and show the result using jstl.

So I input some data in the first html and then after hit the button, then it shows the result in the second page.

What I want to ask is: when I click on the 'back' button of the browser, the value I put in those text boxes are still there, what I want to do is every time I open that page, clear the text boxes and the curso will be in the first text box. How can I do this?

Thanks!!

Here's my two jsp files:
Search-input.jsp
 

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link href="wixIndex.css" rel="stylesheet" type="text/css">

        <title>Web Index</title>

    </head>

    <body>
 

		<%@ include file="header.html" %>
 

        <form name="Name Input Form" action="search-result.jsp">

        	<br> &nbsp;

            <font color="0066CC" size="2"><b>KEYWORD</b></font>  

            &nbsp; &nbsp;

            <input type="text" name="keyword" size="80"/>

            <br><br> &nbsp;

            <font color="0066CC" size="2"><b>CONTENT</b></font>  

            &nbsp; &nbsp;

            <input type="text" name="kwinfo" size="80"/>

            <br><br>
 

            <input type="submit" value="SEARCH" class="button"/>

            <br><br>
 

        </form>
 

    </body>

</html>
 

...................................................................................................................................

...................................................................................................................................
 

Search-result.jsp
 

<%@ taglib prefix="fm" uri="/WEB-INF/matcher.tld"%>
 

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">
 

<jsp:useBean id="matcher" scope="request" class="com.webIndex.match.FindMatch"/>
 

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link href="wixIndex.css" rel="stylesheet" type="text/css">

        <title>Web Index</title>

    </head>

    

	<body>

	

		<%@ include file="header.html" %>

		

	   	<jsp:setProperty name="matcher" property="*" />  

	

		${fm:funMatcher(matcher, matcher.keyword, matcher.kwinfo)}

    	

	</body>

</html>

Open in new window

0
Comment
Question by:Juuno
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:Chad Haney
Chad Haney earned 500 total points
ID: 24778843
Try this:

<body onLoad="javascript:document.forms[0].reset()">
0
 

Author Comment

by:Juuno
ID: 24778861
Yes!!
It works to clear the text boxes. Thanks.
But how can I set the cursor in the first text box in every onLoad?
Thanks!!
0
 
LVL 12

Accepted Solution

by:
Chad Haney earned 500 total points
ID: 24778865
<body onLoad="javascript:document.forms[0].reset();document.forms[0].keyword.focus()">
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

943 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

4 Experts available now in Live!

Get 1:1 Help Now