Pages Navigation Menu

Coding is much easier than you think

How to Reload a Page Only Once Using Javascript

Posted by in JSP | 1 comment

 
Here is a small piece of code that allows to reload a page only once. This is necessary to prevent some data being cached and this is the only solution I found good for my needs. Meta tag no-cache did not save me, and meta tag refresh does not allow to refresh the page only once.
I found this in Google, but I had to spend some hours before I did it. So I think this article will be helpful for you. Here is the code:

<script language="JavaScript" type="text/javascript">
//  Published at: scripts.tropicalpcsolutions.com
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function reloadOnceOnly() {
    if (!reloaded)
        window.location.replace(window.location+"?reloaded=true");
}
//You can call this via the body tag if desired
reloadOnceOnly();
</script>

 

dwd2
Download It – refresh-once
Read More

Resetting a form on page load

Posted by in JSP

<html>
<head>
<title>Resetting a form on page load</title>
<script type="text/javascript" language="javascript">
<!-- //
function ClearForm(){
    document.MyForm.reset();
}
// -->
</script>
</head>
<body onload="ClearForm()">
<table>
<form name="MyForm" action="http://www.java2s.com/" method="Post">
<tr>
 <td width="15%" align="right">First Name: </td>
 <td> <input type="text" name="FirstName"/></td>
</tr>
<tr>
 <td align="right">Last Name: </td>
 <td> <input type="text" name="LastName"/></td>
</tr>
<tr>
 <td align=""right">User Number: </td>
 <td> <input type="text" name="UserNo"/></td>
</tr>
<tr>
 <td> </td>
 <td> <input type="submit" value="Submit Form"/></td>
</tr>
</table>
</form>
</body>
</html>
Read More