472,973 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,973 software developers and data experts.

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 7471
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

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

Similar topics

5
by: Mario Thiel | last post by:
Hello, i am new to JavaScript and right now i am learning Call by Value. i tryed to write a small script but somehow it doesnt work right. i cant put <br> into it, and i can only put the...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
12
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.