Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem in calling a javascript function into a struts jsp page

843838Feb 14 2007 — edited Feb 14 2007
I want to call a javascript function from my jsp page,
I have tried t ocall in many ways, but it is not working. Can any one give me a guidence to do it.

Please find the below code which i am using,

<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/DateTimePicker.js"></script>

using the above line I have called the .js into my jsp

and the following lines are used to call the javascript NewCal function from the DateTimePicker.js.


But my code is not working,

<tr class="datafield" onmouseover="classChange(this,'datafield_h');" onmouseout="classChange(this,'datafield');">
<td class="left"><jlr:label key="buildDate" helpKey="buildDate" /></td>
<td class="right">
<html:text styleId="buildDate" name="vehicleForm" property="vehicleDto.buildDateAsString" size="11" maxlength="8" alt="build date|N|DATE"></html:text>

<img src="<%=request.getContextPath()%>/images/date_picker.gif" name="btnBuildDate"
onClick="javascript:NewCal(document.forms['vehicleForm'].buildDate,'dd/MM/yyyy',false,24)" />
</td>
</tr>

The below is the function present in the DateTimePicker.js file

function NewCal(pCtrl,pFormat,pShowTime,pTimeMode)
{
Cal=new Calendar(dtToday);
if ((pShowTime!=null) && (pShowTime))
{
Cal.ShowTime=true;
if ((pTimeMode!=null) &&((pTimeMode=='12')||(pTimeMode=='24')))
{
TimeMode=pTimeMode;
}
}
if (pCtrl!=null)
Cal.Ctrl=pCtrl;
if (pFormat!=null)
Cal.Format=pFormat.toUpperCase();

exDateTime=document.getElementById(pCtrl).value;
if (exDateTime!="")//Parse Date String
{
var Sp1;//Index of Date Separator 1
var Sp2;//Index of Date Separator 2
var tSp1;//Index of Time Separator 1
var tSp1;//Index of Time Separator 2
var strMonth;
var strDate;
var strYear;
var intMonth;
var YearPattern;
var strHour;
var strMinute;
var strSecond;
//parse month
Sp1=exDateTime.indexOf(DateSeparator,0)
Sp2=exDateTime.indexOf(DateSeparator,(parseInt(Sp1)+1));

if ((Cal.Format.toUpperCase()=="DDMMYYYY") || (Cal.Format.toUpperCase()=="DDMMMYYYY"))
{
strMonth=exDateTime.substring(Sp1+1,Sp2);
strDate=exDateTime.substring(0,Sp1);
}
else if ((Cal.Format.toUpperCase()=="MMDDYYYY") || (Cal.Format.toUpperCase()=="MMMDDYYYY"))
{
strMonth=exDateTime.substring(0,Sp1);
strDate=exDateTime.substring(Sp1+1,Sp2);
}
if (isNaN(strMonth))
intMonth=Cal.GetMonthIndex(strMonth);
else
intMonth=parseInt(strMonth,10)-1;
if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12))
Cal.Month=intMonth;
//end parse month
//parse Date
if ((parseInt(strDate,10)<=Cal.GetMonDays()) && (parseInt(strDate,10)>=1))
Cal.Date=strDate;
//end parse Date
//parse year
strYear=exDateTime.substring(Sp2+1,Sp2+5);
YearPattern=/^\d{4}$/;
if (YearPattern.test(strYear))
Cal.Year=parseInt(strYear,10);
//end parse year
//parse time
if (Cal.ShowTime==true)
{
tSp1=exDateTime.indexOf(":",0)
tSp2=exDateTime.indexOf(":",(parseInt(tSp1)+1));
strHour=exDateTime.substring(tSp1,(tSp1)-2);
Cal.SetHour(strHour);
strMinute=exDateTime.substring(tSp1+1,tSp2);
Cal.SetMinute(strMinute);
strSecond=exDateTime.substring(tSp2+1,tSp2+3);
Cal.SetSecond(strSecond);
}
}
winCal=window.open("","DateTimePicker","toolbar=0,status=0,menubar=0,fullscreen=no,width=250,height=235,resizable=0,top="+cnTop+",left="+cnLeft);
docCal=winCal.document;
RenderCal();
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2007
Added on Feb 14 2007
2 comments
251 views