473,770 Members | 3,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

window.onload() set element value that has not been loaded?

Hi,

Here is my situation. I have a textarea on the page. When the page
loads, I need it to have some default text (which will be generated
dynamically)

so I did something like this

function init()
{
document.getEle mentById("Texar eaID").value = "default text";
}

window.onload
{
init();
}
but the problem is firefox always return "TextAreaID " has no properties
because the textbox hasn't loaded it yet..it seems. How do I get around
that? (I know mabye i can insert the script below the textbox.. but
that's ugly. Any other ways? Thanks

Liming

Aug 26 '05 #1
3 10202
Liming wrote:
Hi,

Here is my situation. I have a textarea on the page. When the page
loads, I need it to have some default text (which will be generated
dynamically)

so I did something like this

function init()
{
document.getEle mentById("Texar eaID").value = "default text";
}

window.onload
{
init();
}
but the problem is firefox always return "TextAreaID " has no properties
because the textbox hasn't loaded it yet..it seems. How do I get around
that? (I know mabye i can insert the script below the textbox.. but
that's ugly. Any other ways? Thanks


1. Be accepting of the ugliness - beauty fades but dumb is forever

2. Use <body onload="init()"

3. Assign init to window.onload in your script element:

window.onload = init; // Note there are no brackets "()"


--
Rob
Aug 26 '05 #2
Rob,

Thanks a lot. I did the third way and it works. If you dont' mind.. how
come window.onload =init works and window.onload{ init(); } is not? Is
there anything speical about it? Sorry, kinda a stupid question,
obvioulsy in this case it made a differnece, i'm just curious if there
are other situations where these two will be different.

Thanks a lot.

Liming

Aug 26 '05 #3
Liming wrote:
Rob,

Thanks a lot. I did the third way and it works. If you dont' mind.. how
come window.onload =init works and window.onload{ init(); } is not? Is
there anything speical about it? Sorry, kinda a stupid question,
obvioulsy in this case it made a differnece, i'm just curious if there
are other situations where these two will be different.


The statement:

function init() { ... }

creates a property of the window object called 'init' that is a function.

The statement - window.onload.i nit; - assigns a *reference* to init to
the window.onload property.

The statement - window.onload.i nit(); - will assign the *result* of
running init() to the window.onload property.

i.e. init() causes the function to be executed immediately (so that the
result can be assigned to the onload property).

You could also do it with an anonymous function:

window.onload = function(){ ... };

You can also add an onload event in a way that will not upset existing
onload events, follow the ideas in this thread:

<URL:http://groups.google.c om/group/comp.lang.javas cript/browse_frm/thread/b58ee83c1510349 7/9c228ec1551ad7e f?tvc=1&q=add+a +function+to+wi ndow.onload+&hl =en#9c228ec1551 ad7ef>


--
Rob
Aug 26 '05 #4

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

Similar topics

12
9382
by: Steve | last post by:
hey guys, i have been searching around... and it seems that the below code is good for a SINGLE PAGE. <BODY BGCOLOR=white onMouseOver="window.status=' something ';return true"> but... i have TONS of pages, and instead of going to each page and
4
7410
by: Eric Osman | last post by:
It seems as though when I use window.open I can't immediately do winId.document.getElementById("someDivTagInTheWindow") because window.open returns to my code before the html in the window is really loaded. What is a good way to synchronize, in other words to have my code know when the window is ready to be interrogated ?
16
10150
by: Konrad Viltersten | last post by:
I have a working script but it gets executed first after the page has finished loading all the images (which may take a while). Since the script is placed in window.onload i understand it has to wait for the loading to get done. However, i wish to execute the script BEFORE all the images had time to get loaded. Is that doable? How? --
6
3041
by: Jure Erznoznik | last post by:
I just spent the whole day on solving this problem but still have no success. This is what i do: ModalDialog.window = window.open("", "error", "toolbar=no,width=" + iWidth + ",height=" + (iHeight + 100) + "," + "left=" + cx + ",top=" + cy + "," + "status=no,resizable=no,modal=yes,dialog=yes");
2
2428
by: John J. Lee | last post by:
I was cheered to see that this guy claims to have solved the problem with onload only firing very late: http://dean.edwards.name/weblog/2005/09/busted/ However, "ash" comments on that page:
26
5694
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized several parts of the DOM, but this does not include the window object. Thank you
7
2074
by: Q | last post by:
Question: why doesn't: window.onLoad = recalculate(); work, and do I have to use: window.onLoad = recalculate; (IE) ???
2
7201
by: funktacular | last post by:
Hi - I have some javascript that works when I run it from a server, but I need to run it locally. When I try to execute it locally I get the following error: Error: uncaught exception: Permission denied to get property Window.processXML Is there a way to get around this issue? default.htm
2
2242
by: Beni Rose | last post by:
I'm trying to open a new window using window.open and then print that window once it's loaded. It works fine in Firefox, but not at all in IE. No matter what I put in my onload, it gets ignored. Here's the code: function openPrintPage(loc) { var printWin = window.open(loc+'? dl=false','printpage','width=600,height=800,location=no,menubar=no,directories=no,status=no,toolbar=no,scrollbars=yes,resizable=yes'); printWin.onload = function()
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9873
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...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
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
6682
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
5313
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...
1
3974
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
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.