Click to See Complete Forum and Search --> : onload()


webrunner
06-25-2003, 03:06 PM
Hi, I am a bit perplexed about the use of javascript for the onload button when I try to execute a function in the onload with onload="javascript:methodname()" or onload="methodname()" however it does not seem to kick off and do what I want when placed in the body when I want it to. Evne stuff that works normally seems not to work in my function why is this. Am I missing something.

David Harrison
06-25-2003, 03:36 PM
well <body onload="methodname();"> should work, but since it doesn't can you post your code?

webrunner
06-25-2003, 03:47 PM
Okay here is for example a code that i know works when I put it by itself in the onload but doesn't work in a function probably because I am doing it wrong.
here it is
function changeurl() {
var urlquery, urlterms, urladdress; urladdressa;

urladdressa="http://128.171.52.55/Help/Register/How_To_Register/How_To_Register.htm";

parent.Help_Frames.location.href=urladdressa;

}
This should work shouldn't it.
When I basically do the same thing in the onload it works.
I am using internet explorer, IIS 5.1

David Harrison
06-25-2003, 04:16 PM
I think I know where it's not working for you. The semi-colon is to signal the end of a line so in the following line of your code:

var urlquery, urlterms, urladdress; urladdressa;

there is a semi-colon after urladdress.

The following is my code, which works in IE6, Opera7 & NS7:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=windows-1252" />

<title>From The Stem Of The Broccoli</title>

<script type="text/javascript"><!--

function changeurl() {
var urlquery, urlterms, urladdress, urladdressa;

urladdressa="http://128.171.52.55/Help/Register/How_To_Register/How_To_Register.htm";

location.href=urladdressa;

}

//--></script>

</head>

<body onload="changeurl();">

<p></p>

</body>

</html>

I had to cut "parent.Help_Frames.location.href" down to "parent.location.href" since I wasn't using frames in my example.

webrunner
06-25-2003, 04:24 PM
It works now don't I feel foolish. If I get something similar I'll post back but I think i should be okay. Thanks Lavalamp.

David Harrison
06-25-2003, 04:31 PM
Your welcome.:)