Hi All,
Iam using RSF(reasonable servlet faces) i need to clear the fields in the form after user submits it using javascript onload function. can anyone please help me.
here is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:rsf="http://ponder.org.uk/rsf">
<head>
<title rsf:id="basic-page-title">Sakai Skin for FlowTalk</title>
<link rsf:id="scr=portal-matter" href="/library/skin/tool_base.css" type="text/css" rel="stylesheet" media="all"/>
<link href="/library/skin/rsmart/tool.css" type="text/css" rel="stylesheet" media="all" rsf:id="scr=portal-matter" />
<style type="text/css">
<!--
.prop {
height:130px;
}
}
-->
</style>
<script>
<!--
var minYear=1940;
var maxYear=2011;
function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
}
return this
}
function dateRange(dtStr){
var daysInMonth = DaysArray(12)
var strMonth=dtStr.substring(2,4)
var strDay=dtStr.substring(0,2)
var strYear=dtStr.substring(4,9)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if(isNaN(dtStr)){
alert("The date format should be : ddmmyyyy")
document.getElementById("dob").value = "";
document.frm.dob.focus();
return false;
}
if (dtStr.length != 8){
alert("The date format should be : ddmmyyyy")
document.getElementById("dob").value = "";
document.frm.dob.focus();
return false;
}
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
document.getElementById("dob").value = "";
document.frm.dob.focus();
return false;
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
document.getElementById("dob").value = "";
document.frm.dob.focus();
return false;
}
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
document.getElementById("dob").value = "";
document.frm.dob.focus();
return false;
}
return true
}
function ValidateForm(){
var dt=document.frmSample.txtDate
if (isDate(dt.value)==false){
dt.focus()
return false
}
return true
}
-->
</script>
<script type="text/javascript" language="JavaScript" >
var busy=0;
function getValid(pf)
{
if(pf=="")
{
alert("please enter a valid pfindexno");
document.getElementById("pfindexno").value="";
return false;
}
if(isNaN(pf))
{
alert("please enter a valid pfindexno");
document.getElementById("pfindexno").value="";
return false;
}
}
function validateDate(strdate)
{
if(8 > strdate.length)
{
alert("Error:Enter Valid Date");
}
if(isNaN(strdate))
{
alert("Error:Enter Valid Date");
}
}
function emailValidator(varaemail){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(!varaemail.match(emailExp))
{
alert("Error: Invalid mail id");
document.getElementById("input").value="";
return false;
}
}
function newWindow(newContent){
winContent = window.open(newContent, 'nextWin', 'right=0, top=20,width=750,height=600, toolbar=no,scrollbars=yes, resizable=no') }
function showSdateCal()
{
var string2 = "dob";
//alert(string2);
var string2val = document.getElementById(string2).value;
var dt;
if((null == string2val) || (string2val.length == 0)) dt = new Date();
else dt = new Date(document.getElementById(string2).value);
if (!isNaN(dt))
{
var cal2 = new calendar2(document.getElementById(string2));
cal2.popup();
document.getElementById(string2).select();
}
}
function clearOnly()
{
document.getElementById("pfindexno").value="";
document.getElementById("dob").value="";
document.getElementById("input").value="";
}
</script>
</head>
<body rsf:id="scr=sakai-body" onload="clearOnly();">
<div class="portletBody">
<div class="toplinkSbi">
<a href="/xsl-portal" target="_parent" rsf:id="msg=mainText2">Home</a>
</div>
<div class="sbiHeader">
<div class="topSbi">
</div>
</div>
<div class="navIntraTool" width="100%">
<h3 rsf:id="msg=mainTitle">reset your password</h3></div>
<div class="navIntraTool" width="100%">
<span><strong>Fields with</strong><span style="color: red; font-weight: bold;"> * </span><strong>are mandatory</strong></span>
</div>
<form rsf:id="form" name="forgot">
<div rsf:id="error-row:">
<div class="alertMessage" rsf:id="error"></div>
</div>
<br/>
<table align="center">
<tr>
<td style="color: red;">*</td>
<td><label rsf:id="msg=formLabel" >PF </label></td>
<td><input rsf:id="pfindexno" id="pfindexno" type="text" onBlur = "getValid(this.value);"/></td>
<td> </td>
</tr>
<tr>
<td style="color: red;">*</td>
<td><label rsf:id="msg=formLabel3" >Date </label></td>
<td><input rsf:id="dob" id="dob" type="text" onBlur = "dateRange(this.value);"/></td>
<td><font color="blue" rsf:id="msg=formLabel5">Format</font></td>
</tr>
<tr>
<td style="color: red;">*</td>
<td><label rsf:id="msg=formLabel2">email</label></td>
<td><input rsf:id="input" id="input" type="text" onBlur = "emailValidator(this.value);" /></td>
<td> </td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td> </td>
<td align="center"> </td>
<td align="center"><input name="submit" type="submit" value="Submit" rsf:id="submit" /></td>
<td> </td>
</tr>
<tr><td> <div class="prop"> </div></td></tr>
<div align="center" id="footer">
<div class="footerExtNav" align="center"></div>
<div id="footerInfo">
<span class="skip"></span>
<br />
</div>
</div>
</table>
</form>
</div>
</body>
</html>