bharat_tcs
asked on
forms gets submitted
below is the code..if i click on new i validate a date and call a fucntion which returns false if invalid. the thing is that if get an alert ("Invalid date") the form gets submitted/refreshed and values input by user gets lost ..can some one help
<html>
<head>
<title> Request Line Window </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript1.2">
var field1='<%=request.getPara
var field2='<%=request.getPara
var field3='<%=request.getPara
var field4='<%=request.getPara
var field5='<%=request.getPara
var field6='<%=request.getPara
field1='requestAction';
field2='requestCategory';
field3='requestEntity';
field4='requestClass';
field5='requestDollar';
field6='requestTermination
function validateDollarChange()
{
if (document.lineItemForm.sel
{
document.lineItemForm.doll
}else
{
document.lineItemForm.doll
}
}
function test(requestActionVar)
{
var categoryOptionScriptVar = "";
var sigClassOptionScriptVar = "";
var terminationDateVar = "";
var signatoryTypeScriptVar = "";
var signatoryIdScriptVar = "";
var entityOptionScriptVar = "";
var dollarOptionScriptVar ="";
var effectiveDate = document.lineItemForm.term
//alert(effectiveDate);
if (!validDates(effectiveDate
{
alert("Please select a Valid Date");
return true;
}
else
{
//alert(document.lineItemF
//opener.addRequestItem(re
for (var i= 0;i < document.lineItemForm.selE
{
if(document.lineItemForm.s
{
// alert("in for loop");
categoryOptionScriptVar = document.lineItemForm.selC
//alert(categoryOptionScri
entityOptionScriptVar = entityOptionScriptVar + document.lineItemForm.selE
//alert(entityOptionScript
sigClassOptionScriptVar = document.lineItemForm.selS
//alert(sigClassOptionScri
//dollarOptionScriptVar=do
// alert(dollarOptionScriptVa
terminationDateVar = document.lineItemForm.term
//alert(terminationDateVar
if(document.lineItemForm.s
{
dollarOptionScriptVar=docu
}
else
{
dollarOptionScriptVar=docu
}
// alert("dollarOptionScriptV
}
}
opener.addRequestIntItem(r
window.close();
}
}
function validDates(effectiveDate)
{
var effective_year = effectiveDate.substring(7,
var effective_mon = effectiveDate.substring(0,
var effective_day = effectiveDate.substring(4,
//alert(effectiveDate);
var sDate = new Date(effectiveDate);
var currentDate = new Date();
//alert(currentDate);
var currentDates = "" +currentDate;
var current_year = currentDates.substring(24,
var current_mon = currentDates.substring(4,7
var current_day = currentDates.substring(8,1
var currentDates1 = current_mon + " " +current_day + ", " + current_year;
//alert(currentDates1);
var cDate = new Date(currentDates1);
var latest_year = currentDate.getYear() +2;
var latest_mon = current_mon;
var latest_day = current_day;
var latestDate = latest_mon + " " + latest_day + ", " + latest_year;
alert(latestDate);
var eDate= new Date(latestDate)
var terminationDateValue ="";
//check if Date is blank assign 2 years from Current Date
//alert(sDate);
//alert(cDate);
//alert(eDate);
if( effectiveDate == "")
{
alert("when eff date blank" );
document.lineItemForm.term
return true;
}
else if(sDate < cDate)
{
alert("Please select a valid Date greater than Today");
document.lineItemForm.term
return false;
}
else if(sDate > eDate)
{
alert(effectiveDate);
alert(latestDate);
alert(" Please select a valid Date less than 2 years");
document.lineItemForm.term
return false;
}
else
{
//alert("Valid Date");
// document.lineItemForm.term
return true;
}
}
</script>
<SCRIPT FOR=window EVENT=onload LANGUAGE="JScript">
document.lineItemForm.doll
</SCRIPT>
<%
String signatoryTypeVar = "";
String signatoryIdVar = "";
if (request.getParameter("sig
{
signatoryTypeVar = request.getParameter("sign
}
if (request.getParameter("sig
{
signatoryIdVar = request.getParameter("sign
}
//int selectedEntityInt = 0;
//String selectedEntity = "";
//if (request.getParameter("hid
//{
// selectedEntity = request.getParameter("hidd
// try {
// selectedEntityInt = Integer.parseInt(selectedE
// }
// catch (NumberFormatException badFormatSelectedIndex)
// {
// selectedEntityInt = 0;
// }
//}
//int selectedCategoryInt = 0;
//String selectedCategory = "External";
//if (request.getParameter("hid
//{
// selectedCategory = request.getParameter("hidd
// try {
// selectedCategoryInt = Integer.parseInt(selectedC
// }
// catch (NumberFormatException badFormatSelectedIndex)
// {
// selectedCategoryInt = 0;
// }
//}
//String keyValuesSubmitted = "";
//if (request.getParameter("key
//{
// keyValuesSubmitted = request.getParameter("keyV
//}
// Parameters for the actual values -not their indexes - selected in the list boxes
//String selectedEntityText = "ALL";
//if (request.getParameter("sel
//{
// selectedEntityText = request.getParameter("sele
//}
//String selectedCategoryText = "ALL";
//if (request.getParameter("sel
//{
// selectedCategoryText = request.getParameter("sele
//}
%>
</head>
<jsp:usebean id="sigstatic"
class="com.lehman.tres.sig
scope="request" />
<%
// GET VALID VALUES OF THE VARIOUS STATIC DATA ELEMENTS
// FIRST LIST OF ENTITIES
String genericOptionXsl ="../wls61/config/etg/appl
String sigClassOptionXsl="../wls6
String strEntityXML = "";
try {
strEntityXML = sigstatic.generateXMLStati
}
catch(Exception e)
{
out.println ( "Error: error calling generateXMLStaticDataList with param entity ");
}
// NEXT LIST OF CATEGORIES
String strCategoryXML ="";
try {
strCategoryXML = sigstatic.generateXMLStati
}
catch(Exception e)
{
out.println ( "Error: error calling generateXMLStaticDataList with param category");
}
%>
<body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
<form name="lineItemForm">
<input type="hidden" name="keyValuesSubmittedBo
<input type="hidden" name="signatoryId" value=<%=signatoryIdVar %> >
<input type="hidden" name="signatoryType" value=<%=signatoryTypeVar %> >
<input type="hidden" name="terminationDate2" value="?" >
<table width="740" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="10" rowspan="99"><img src="/LL_S/imagelibrary/sp
height="1" width="10" border="0"></td>
<td width="309" height="37" valign="top" align="left"><img src="/LL_S/imagelibrary/lo
<!-- <td width="309" height="37" valign="top" align="left"><<img src="/LL_S/imagelibrary/lo
<td width="10" rowspan="99"><img src="/LL_S/imagelibrary/sp
</tr>
<tr>
<td class="bggray" height="1" valign="top"><img src="/LL_S/imagelibrary/sp
</tr>
<tr>
<td height="10"><img src="/LL_S/imagelibrary/sp
</tr>
<tr>
<td bgcolor="#FFFFFF" width="100%" align="center">
<!-- Nugget Code for Pop Up Goes here!!! -->
<table width="100%" cellpadding="1" cellspacing="0" border="0" class="bggray">
<tr><td>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="bgcoolgray">
<tr>
<td class="bggray" colspan="3" height="22" valign="middle"><span class="a14white"> Sig
</tr>
<tr>
<td width="5" rowspan="2"><img src="/LL_S/imagelibrary/ar
<td height="5"><img src="/LL_S/imagelibrary/ar
<td width="5" rowspan="2"><img src="/LL_S/imagelibrary/ar
</tr>
<tr>
<td>
<table width="100%" cellpadding="2" cellspacing=0 border=0>
<tr>
<td><span class="headingTwo"> C
<td><span class="headingTwo"> E
<td><span class="headingTwo"> C
<td><span class="headingTwo"> D
<td><span class="headingTwo"> T
</tr>
<tr>
<td colspan="1">
<input name="selCategory" class="formtext" value="Internal" readonly>
<%
// out.println(XSLTransformer
%>
</td>
<td colspan="1">
<select name="selEntity" multiple class="formtext" >
<%
out.println(XSLTransformer
%>
</td>
<td colspan="1">
<input name="selSigClass" class="formtext" value="I" readonly>
</td>
<td colspan="1">
<SELECT name="selSigDollar" class="formtext" onchange="validateDollarCh
<OPTION value="<$999,999.99">Up to $999,999.99</OPTION>
<OPTION value="<$9,999,999.99">Up to $9,999,999.99</OPTION>
<OPTION value="<$49,999,999.99">Up
<OPTION value=">$50,000,000 ">$50,000,000 and over</OPTION>
<OPTION value="Other">Other</OPTIO
</SELECT>
</td>
<td nowrap valign="middle" >
<INPUT name="terminationDate" size="25" type="text" value="" class="formtext" readonly>
<img border="0" style="cursor: hand;" onClick="openCalendar('ter
</td>
</tr>
<!-- added for Textbox-->
<tr>
<td colspan="4" align="right"><input name="dollarlimittxt" display="none" type="text" value="Enter a Dollar Limit Value"/></td>
</tr>
</table>
<!-- NOW ADD BUTTONS - NEW IF NO EXISTING POWER FOUND; UPDATE OR REMOVE IF EXISTING POWER FOUND -->
</td></tr>
<tr>
<!-- add appropriate buttons -->
<td colspan="3" height="5"><img src="/LL_S/imagelibrary/ar
</tr>
<tr>
<td colspan="3" class="bgceladon" height="22" align="right" valign="middle"> <img src="/LL_S/imagelibrary/ar
" alt="Transparent Spacer " border="0" height="18" width="5">
<input type="image" src="/LL_S/imagelibrary/bu
onClick="javascript:test('
<img src="/LL_S/imagelibrary/ar
<tr>
</table>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.