473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 7500
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.