I need this function to happen when page loads vs OnClick

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
Greystone
Forum Newbie
Posts: 1
Joined: Tue Nov 10, 2009 1:23 pm

I need this function to happen when page loads vs OnClick

Post by Greystone »

I was giving this chore, I need the function fun() to just happen vs the OnClick

Any help will be apprecated

Code: Select all

 
<script language="JavaScript">
 function fun() {
   window.parent.main.cols="200,*";
   parent.list.location="../chanlist.php";
 }
 
 
</script>
 <input type=image src="../images/click1.gif" onClick="fun()" alt="StarChat Channels - Click here for the current channels list" border="0">
  </td>
 
  <td valign="top">
   <form name="jform">
 
 
ceiroa
Forum Newbie
Posts: 11
Joined: Thu Oct 08, 2009 4:14 pm

Re: I need this function to happen when page loads vs OnClick

Post by ceiroa »

You can register the function with the Window object as an "onload" event handler:

Code: Select all

 window.onload = fun;
You can put that at the top of your javascript code, right before the function definition.

Using a library such as JQuery or Dojo would be recommended, as they provide functions that do an even better job, calling the functions you want the instant the DOM is ready to be read and manipulated, and avoiding browser incompatibilities headaches.

You can find the one from JQuery here: http://docs.jquery.com/Events/ready#fn
---------------
Carlos R. M. Eiroa
PHP Consultant
Post Reply