473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to access javascript function on <body> from <head>

Hello everyone. Hope ya'll had a nice New Year. Anyway, my question
is why won't this work? I must be doing something dumb . . . here is
the code:

in the body tag, I have this code (just to test):

<script LANGUAGE="javas cript">
<!--
function hiThere() {
alert("hi");
return true;
}
//-->
</script>

in the head section, I have this code:

<script LANGUAGE="javas cript">
<!--
document.body.o nload=hiThere() ;
//-->
</script>

By the way, I know someone will comment, by "does not work, I mean on
the load of the page, the alert is not displayed, nor are any errors.
Thanks for any help you can offer.

Have a great day!
Ryan

Jul 23 '05 #1
2 2043


ry*********@gma il.com wrote:

in the body tag, I have this code (just to test):

<script LANGUAGE="javas cript">
<!--
function hiThere() {
alert("hi");
return true;
}
//-->
</script>

in the head section, I have this code:

<script LANGUAGE="javas cript">
<!--
document.body.o nload=hiThere() ;
//-->
</script>

By the way, I know someone will comment, by "does not work, I mean on
the load of the page, the alert is not displayed, nor are any errors.


You should get errors, with script in the head
document.body
should be null so
document.body.o nload
alone should trow an error.
And trying to call
hiThere()
in a script block before the script block that defines the function
hiThere should also cause an error.
If you want to use a function in a script block make sure it is defined
inside the same script block or in an earlier script block.

As for
document.body.o nload=hiThere() ;
you probably want
document.body.o nload=hiThere;
but for most browsers you need
window.onload = hiThere
anyway (of course that works only if the function is already defined).
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Thanks for the reply Martin! Duh, I don't know what I was thinking.

What I am trying to do is render a javascript block in asp . . . but
that is a post for another group. I was thinking I could test what I
was trying to accomplish this way.

Anyway, thanks again!
Ryan

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
6857
by: Brian W | last post by:
Hi All, I have a web user control that, among other things, provides Print this page, and Email this page functionality I have this script that is to execute on the click of the asp:hyperlinks I have a function in a <SCRIPT> block that I want in the <head></head> section of the page. Unfortunately, RegisterClientScriptBlock, RegisterStartupScript don't always work, and when they do the script is placed inside the <form> tag (this...
6
5468
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of the page dynamically when the page is rendered? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
3
1455
by: phpmel | last post by:
Hi guys, I have yet another question. I am working with this html form that uses a template. <head> //is greyed out //some greyed out <style >stuff is next <!-- InstanceEndEditable -->//greyed out </head>//greyed out <body>//greyed out
23
2237
by: Xah | last post by:
Here's a interesting case of invalid html 4 strict file. In summary, if you have <body></bodywithout any content, the file would be invalid under html 4 strict. Valid if html 4 lose. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/ TR/html4/strict.dtd"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=utf-8">
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.