View Full Version : Having problems with "onLoad"?

12-02-2005, 10:56 PM
I have no idea why the following code does not work in Explorer. It works okay in Firefox. In Explorer, the text box is blank. The onload function seems to not be executed since it is not displaying the value.

Any suggestions?

Code below:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function fnLoadSetup()
document.userForm.sInit_Text.value = "Text Here";
<body bgcolor="#CCCCCC" text="#000000" onLoad="fnLoadSetup()">
<form name="userForm" method="post" action="">
<input type="text" name="sInit_Text" readonly>

12-02-2005, 11:06 PM
Well, firstly <script language="JavaScript"> is not valid. <script type="text/javascript"> Should replace it.

You could give the text box an ID -

<input type="text" name="sInit_Text" id="sInit_Text" readonly>

And see if that helps?

Or then try replacing the javascript with -

document.getElementById("sInit_Text").value="Text Here";

12-02-2005, 11:11 PM
That didn't work. This code works okay when I run it through my webserver in an asp file however it doesn't work as an html file.

12-02-2005, 11:15 PM
Well your original HTML works fine for me in IE... are you sure you have Javascript enabled (don't mean to sound patronising)?

You could set the original value without Javascript like so if that helps -

<input type="text" value="Text Here" name="sInit_Text" readonly>

12-03-2005, 12:35 AM
Thanks for your help. It turns out my javascript was not enabled (well actually the java settings was set at "Medium Safety", and I changed it to "Low Safety" to make it work).

I have between running the same files as "asp" files, and there is tons of javascript that is executed since these files upload data, and I use javascript to display the data. I converted one of the asp files to html and deleted the upload commands and hardcoded values into the javascript. I am surprised that the html files did not execute the javascript functions since there were no problems executing them when the file was an "asp" file.

It is working now. Thanks again for your help!!!

12-03-2005, 12:42 AM
No prob, are you running these offline to test by the way? Because instead of changing the security level you could try unticking the box Tools>Internet Options>Advanced>Security>Allow active content to run in files on My Computer.