PC Review


Reply
Thread Tools Rate Thread

Calling JavaScript

 
 
Trevor L.
Guest
Posts: n/a
 
      21st Jan 2005
I have a script which generates the date. (I could attach
it but it is straightforward for those who know
JavaScript)

How do I call this from the HTML code inside the <body>
tag,
e.g.
<p>Welcome. Todays date is XXXXXXXXXXXX </p>

What to do I put in place of XXXXXXXXXXXX to display the
date?

At the moment I am putting the entire script. This is a
bit of overkill.

The code looks like this
<html>

<head>
</head>

<body>

<p>Welcome. Todays date is&nbsp;
<script language="JavaScript">
<!--
(the script goes in here)
//-->
</script>
</p>

</body>
</html>

The result is
Welcome. Todays date is Friday, January 21, 2005


 
Reply With Quote
 
 
 
 
Steve Easton
Guest
Posts: n/a
 
      21st Jan 2005
Not as easy to say as you think without seeing the script.
If the script is using document.all.tagid.innerHTML= "what to write";
Where tagid = the id assigned to the <p tag like this" id=tagid"
and where what to write = the actual portion of the script that generates the date.

The you could launch the script by adding this to the body tag: <body onload="functionname()">
Where functionname() = the function that starts the script.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Trevor L." <(E-Mail Removed)> wrote in message
news:145001c4ff8b$19bcff10$(E-Mail Removed)...
> I have a script which generates the date. (I could attach
> it but it is straightforward for those who know
> JavaScript)
>
> How do I call this from the HTML code inside the <body>
> tag,
> e.g.
> <p>Welcome. Todays date is XXXXXXXXXXXX </p>
>
> What to do I put in place of XXXXXXXXXXXX to display the
> date?
>
> At the moment I am putting the entire script. This is a
> bit of overkill.
>
> The code looks like this
> <html>
>
> <head>
> </head>
>
> <body>
>
> <p>Welcome. Todays date is&nbsp;
> <script language="JavaScript">
> <!--
> (the script goes in here)
> //-->
> </script>
> </p>
>
> </body>
> </html>
>
> The result is
> Welcome. Todays date is Friday, January 21, 2005
>
>



 
Reply With Quote
 
Bob Lehmann
Guest
Posts: n/a
 
      21st Jan 2005
>> If the script is using document.all.tagid.innerHTML= "what to write";
This would only work in IE.

document.getElementById(tagid).innerHTML

Bob Lehmann


"Steve Easton" <(E-Mail Removed)> wrote in message
news:%23yHUFS7$(E-Mail Removed)...
> Not as easy to say as you think without seeing the script.
> If the script is using document.all.tagid.innerHTML= "what to write";
> Where tagid = the id assigned to the <p tag like this" id=tagid"
> and where what to write = the actual portion of the script that generates

the date.
>
> The you could launch the script by adding this to the body tag: <body

onload="functionname()">
> Where functionname() = the function that starts the script.
>
> --
> Steve Easton
> Microsoft MVP FrontPage
> 95isalive
> This site is best viewed............
> .......................with a computer
>
> "Trevor L." <(E-Mail Removed)> wrote in message
> news:145001c4ff8b$19bcff10$(E-Mail Removed)...
> > I have a script which generates the date. (I could attach
> > it but it is straightforward for those who know
> > JavaScript)
> >
> > How do I call this from the HTML code inside the <body>
> > tag,
> > e.g.
> > <p>Welcome. Todays date is XXXXXXXXXXXX </p>
> >
> > What to do I put in place of XXXXXXXXXXXX to display the
> > date?
> >
> > At the moment I am putting the entire script. This is a
> > bit of overkill.
> >
> > The code looks like this
> > <html>
> >
> > <head>
> > </head>
> >
> > <body>
> >
> > <p>Welcome. Todays date is&nbsp;
> > <script language="JavaScript">
> > <!--
> > (the script goes in here)
> > //-->
> > </script>
> > </p>
> >
> > </body>
> > </html>
> >
> > The result is
> > Welcome. Todays date is Friday, January 21, 2005
> >
> >

>
>



 
Reply With Quote
 
Bob Lehmann
Guest
Posts: n/a
 
      21st Jan 2005
Meant to say...

This would be better -
document.getElementById(tagid).innerHTML

Bob Lehmann

"Bob Lehmann" <(E-Mail Removed)> wrote in message
news:eCP0L97$(E-Mail Removed)...
> >> If the script is using document.all.tagid.innerHTML= "what to write";

> This would only work in IE.
>
> document.getElementById(tagid).innerHTML
>
> Bob Lehmann
>
>
> "Steve Easton" <(E-Mail Removed)> wrote in message
> news:%23yHUFS7$(E-Mail Removed)...
> > Not as easy to say as you think without seeing the script.
> > If the script is using document.all.tagid.innerHTML= "what to write";
> > Where tagid = the id assigned to the <p tag like this" id=tagid"
> > and where what to write = the actual portion of the script that

generates
> the date.
> >
> > The you could launch the script by adding this to the body tag: <body

> onload="functionname()">
> > Where functionname() = the function that starts the script.
> >
> > --
> > Steve Easton
> > Microsoft MVP FrontPage
> > 95isalive
> > This site is best viewed............
> > .......................with a computer
> >
> > "Trevor L." <(E-Mail Removed)> wrote in message
> > news:145001c4ff8b$19bcff10$(E-Mail Removed)...
> > > I have a script which generates the date. (I could attach
> > > it but it is straightforward for those who know
> > > JavaScript)
> > >
> > > How do I call this from the HTML code inside the <body>
> > > tag,
> > > e.g.
> > > <p>Welcome. Todays date is XXXXXXXXXXXX </p>
> > >
> > > What to do I put in place of XXXXXXXXXXXX to display the
> > > date?
> > >
> > > At the moment I am putting the entire script. This is a
> > > bit of overkill.
> > >
> > > The code looks like this
> > > <html>
> > >
> > > <head>
> > > </head>
> > >
> > > <body>
> > >
> > > <p>Welcome. Todays date is&nbsp;
> > > <script language="JavaScript">
> > > <!--
> > > (the script goes in here)
> > > //-->
> > > </script>
> > > </p>
> > >
> > > </body>
> > > </html>
> > >
> > > The result is
> > > Welcome. Todays date is Friday, January 21, 2005
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Steve Easton
Guest
Posts: n/a
 
      21st Jan 2005
Thanks Bob.
I tend to forget about the "other" browsers.

;-)

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Bob Lehmann" <none> wrote in message news:eKCEMo8$(E-Mail Removed)...
> Meant to say...
>
> This would be better -
> document.getElementById(tagid).innerHTML
>
> Bob Lehmann
>
> "Bob Lehmann" <(E-Mail Removed)> wrote in message
> news:eCP0L97$(E-Mail Removed)...
> > >> If the script is using document.all.tagid.innerHTML= "what to write";

> > This would only work in IE.
> >
> > document.getElementById(tagid).innerHTML
> >
> > Bob Lehmann
> >
> >
> > "Steve Easton" <(E-Mail Removed)> wrote in message
> > news:%23yHUFS7$(E-Mail Removed)...
> > > Not as easy to say as you think without seeing the script.
> > > If the script is using document.all.tagid.innerHTML= "what to write";
> > > Where tagid = the id assigned to the <p tag like this" id=tagid"
> > > and where what to write = the actual portion of the script that

> generates
> > the date.
> > >
> > > The you could launch the script by adding this to the body tag: <body

> > onload="functionname()">
> > > Where functionname() = the function that starts the script.
> > >
> > > --
> > > Steve Easton
> > > Microsoft MVP FrontPage
> > > 95isalive
> > > This site is best viewed............
> > > .......................with a computer
> > >
> > > "Trevor L." <(E-Mail Removed)> wrote in message
> > > news:145001c4ff8b$19bcff10$(E-Mail Removed)...
> > > > I have a script which generates the date. (I could attach
> > > > it but it is straightforward for those who know
> > > > JavaScript)
> > > >
> > > > How do I call this from the HTML code inside the <body>
> > > > tag,
> > > > e.g.
> > > > <p>Welcome. Todays date is XXXXXXXXXXXX </p>
> > > >
> > > > What to do I put in place of XXXXXXXXXXXX to display the
> > > > date?
> > > >
> > > > At the moment I am putting the entire script. This is a
> > > > bit of overkill.
> > > >
> > > > The code looks like this
> > > > <html>
> > > >
> > > > <head>
> > > > </head>
> > > >
> > > > <body>
> > > >
> > > > <p>Welcome. Todays date is&nbsp;
> > > > <script language="JavaScript">
> > > > <!--
> > > > (the script goes in here)
> > > > //-->
> > > > </script>
> > > > </p>
> > > >
> > > > </body>
> > > > </html>
> > > >
> > > > The result is
> > > > Welcome. Todays date is Friday, January 21, 2005
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Murray
Guest
Posts: n/a
 
      21st Jan 2005
<p>Today's date is <script
type="text/javsacript">document.write(yourfunctionname())</script>, and
you'd better believe it!</p>

--
Murray

"Trevor L." <(E-Mail Removed)> wrote in message
news:145001c4ff8b$19bcff10$(E-Mail Removed)...
>I have a script which generates the date. (I could attach
> it but it is straightforward for those who know
> JavaScript)
>
> How do I call this from the HTML code inside the <body>
> tag,
> e.g.
> <p>Welcome. Todays date is XXXXXXXXXXXX </p>
>
> What to do I put in place of XXXXXXXXXXXX to display the
> date?
>
> At the moment I am putting the entire script. This is a
> bit of overkill.
>
> The code looks like this
> <html>
>
> <head>
> </head>
>
> <body>
>
> <p>Welcome. Todays date is&nbsp;
> <script language="JavaScript">
> <!--
> (the script goes in here)
> //-->
> </script>
> </p>
>
> </body>
> </html>
>
> The result is
> Welcome. Todays date is Friday, January 21, 2005
>
>



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      22nd Jan 2005
Hi Steve, Bob, Murray

All the script does is calculate the date into the variable today. The last
statement is
document.write(today)

Here it is in full. (I don't understand it all as yet, but that doesn't
matter.)

<script language="JavaScript">
<!--
var now = new Date();
var days = new Array(
'Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
var months = new Array(
'January','February','March','April','May',
'June','July','August','September','October',
'November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;}

today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear()));

document.write(today);
//-->
</script>


Murray,
I used your suggestion

I named the function TodaysDate(), changed the last line to return (today)
and placed it in the <head> section

In the body I did exactly as you said, i.e.
<p>Today's date is
<script type="text/javascript">document.write(TodaysDate())</script>
, and you'd better believe it!</p>

It returned:
Today's date is Saturday, January 22, 2005 , and you'd better believe it!
as hoped for

Steve and Bob,
I don't understand your suggestions as yet.
The script is not using document.all.tagid.innerHTML

With a bit of experimentation, it may become clear
--
Thanks to all,
Trevor L.


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html


 
Reply With Quote
 
Steve Easton
Guest
Posts: n/a
 
      22nd Jan 2005
To get the script to do what you want as it is written, place it in a single cell table, or a cell
within a table like this.

<table border="0" cellpadding="0" cellspacing="0" width="200" height="20">
<tr>
<td align="center">
<script language="JavaScript">
<!--
var now = new Date();
var days = new Array(
'Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
var months = new Array(
'January','February','March','April','May',
'June','July','August','September','October',
'November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;}

today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear()));

document.write(today);
//-->
</script>
</td>
</tr>
</table>


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Trevor L." <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Hi Steve, Bob, Murray
>
> All the script does is calculate the date into the variable today. The last
> statement is
> document.write(today)
>
> Here it is in full. (I don't understand it all as yet, but that doesn't
> matter.)
>
> <script language="JavaScript">
> <!--
> var now = new Date();
> var days = new Array(
> 'Sunday','Monday','Tuesday','Wednesday',
> 'Thursday','Friday','Saturday');
> var months = new Array(
> 'January','February','March','April','May',
> 'June','July','August','September','October',
> 'November','December');
> var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
>
> function fourdigits(number) {
> return (number < 1000) ? number + 1900 : number;}
>
> today = days[now.getDay()] + ", " +
> months[now.getMonth()] + " " +
> date + ", " +
> (fourdigits(now.getYear()));
>
> document.write(today);
> //-->
> </script>
>
>
> Murray,
> I used your suggestion
>
> I named the function TodaysDate(), changed the last line to return (today)
> and placed it in the <head> section
>
> In the body I did exactly as you said, i.e.
> <p>Today's date is
> <script type="text/javascript">document.write(TodaysDate())</script>
> , and you'd better believe it!</p>
>
> It returned:
> Today's date is Saturday, January 22, 2005 , and you'd better believe it!
> as hoped for
>
> Steve and Bob,
> I don't understand your suggestions as yet.
> The script is not using document.all.tagid.innerHTML
>
> With a bit of experimentation, it may become clear
> --
> Thanks to all,
> Trevor L.
>
>
> I choose Polesoft Lockspam to fight spam, and you?
> http://www.polesoft.com/refer.html
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Javascript srini.venkatesan@gmail.com Microsoft ASP .NET 5 6th Oct 2006 05:27 AM
Calling javascript from C#--help please Bishoy George Microsoft ASP .NET 10 5th Oct 2005 10:36 PM
Calling WS from Javascript Ganesh Ramamurthy Microsoft ASP .NET 5 13th Dec 2004 05:41 AM
Calling JavaScript from C# Jakub Gutkowski Microsoft C# .NET 3 16th Nov 2003 10:34 PM
Re: Calling .NET Assembly from JavaScript... Ken Dopierala Jr. Microsoft ASP .NET 0 22nd Jul 2003 08:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.