468,720 Members | 1,884 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

how to call javascript when using document.write function

hi all,
iam new to javascript. i have problem calling javascript functions.iam designing a calender page.here is my code.
[HTML]<%@ page import='java.io.*,java.util.*,java.sql.*,javax.ser vlet.*,javax.servlet.http.*' session='true'%>
<%@ page import='java.text.*'%>
<html>
<script language='javascript'>
function backward()
{
alert("hello");
}
function forward()
{
alert("in forward");
}
function display()
{
var months=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec");
var weekdays=new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat");
var givenmonth=document.frm.month.value;//alert(givenmonth);
var givendate=document.frm.date.value;//alert(givendate);
var datelimit;
var today=new Date();//alert(today);
var temp=new String(today);//alert(temp);
var todayday=temp.substring(0,3);//alert(todayday);
var todaymonth=temp.substring(4,7);//alert(todaymonth);
var todaydate=temp.substring(8,10);alert(todaydate);
var start=todaydate-7;//alert("start="+start);
var firstday,firstbrk,secondbrk,thirdbrk,fourthbrk;
if(start<7)
{
firstday=weekdays[start-1];
//alert("firstday"+firstday);
}
firstbrk=8-start;secondbrk=firstbrk+7;thirdbrk=secondbrk+7;fo urthbrk=thirdbrk+7;
if(givenmonth=='Jan' ||givenmonth=='Mar' ||givenmonth=='May' || givenmonth=='Jul' || givenmonth=='Aug' || givenmonth=='Oct' || givenmonth=='Dec')
{
datelimit=31;//alert(datelimit);
}
if(givenmonth=='Apr' ||givenmonth=='Jun' ||givenmonth=='Sep' || givenmonth=='Nov')
{
datelimit=30;//alert(datelimit);
}
if(givenmonth=='Feb')
{
datelimit=28;//alert(datelimit);
}
document.write("<table border=1>"+"<tr>"+"<td colspan=2>");
document.write("<input type=button name=button value=Back onclick=>"+"</td>");
document.write("<td colspan=3>"+"<input type=text name=month value=Nov>"+"</td>");
document.write("<td colspan=2>"+"<img src=e_forward.gif onclick=forward()>"+"</td>"+"</tr>");
document.write("<tr>");
for(var a=0;a<weekdays.length;a++)
{
document.write("<td>"+weekdays[a]+"</td>");
}
document.write("</tr><tr>");
for(var a=1;a<start;a++)
{
document.write("<td></td>");
}
for(var a=1;a<datelimit;a++)
{
document.write("<td>");
if(todaydate==a)
{
document.write("<font color=red>");
}
if(givendate==a && todaymonth==givenmonth)
{
document.write("<font color=blue>");
}
document.write(a);
if(a==firstbrk || a==secondbrk || a==thirdbrk || a==fourthbrk)
document.write("</td></tr>");
}
document.write("</table>");
}

</script>
<body bgcolor='#fofofo'>
<form name='frm'>
<%!
String entereddate,enteredyear,enteredmonth,enteredday;
%>
<%
entereddate=request.getParameter("entereddate");
out.println("entereddate"+entereddate);
StringTokenizer stz1=new StringTokenizer(entereddate,"-");
enteredyear=stz1.nextToken();out.println("enteredy ear="+enteredyear);
if(stz1.hasMoreTokens()){
enteredmonth=stz1.nextToken();out.println("entered month="+enteredmonth);
enteredday=stz1.nextToken();out.println("enteredda y="+enteredday);
}
%>
<BR>
Month:<input type='text' name='month' value='<%=enteredmonth%>'>
<BR>
Date:<input type='text' name='date' value='<%=enteredday%>'>
<BR>
<input type='button' name='button' value='display' onclick='display()'>
</form>
</body>
</html>[/HTML]

the backward and forward functions ar giving errors pls help
Nov 12 '07 #1
1 6841
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

You can't use document.write after the page has loaded.

Create the table and append to the body/a div using appendChild, or you could even use innerHTML, or have the calendar ready and just display when needed.
Nov 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Mario Thiel | last post: by
4 posts views Thread by JesusFreak | last post: by
19 posts views Thread by dmiller23462 | last post: by
8 posts views Thread by chrisdude911 | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.