Re: javascript in <head> or in <body> ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



C.R.Vegelin wrote:
Are there any rules when to include javascript in <head> or in <body> ?
For example, <script type="text/javascript">
function reload(form)
{ var val=form.Chapter.options[form.Chapter.options.selectedIndex].value; self.location='QueryForm.php?Chapter=' + val ;
}
</script>


Generally, script blocks outside of the head are meant to be used for routines that run as the page is loading. For example, one might have some JS that creates some block of HTML or something. Or one might have a JS block at the very end of the page that is meant to run once the page has (almost) completed loading. Why people do this, i'm not sure. Personally, i think script blocks belong in the head. If you have some function that needs to run at page load, there's the onload handler for that.

In your case, it looks like that function could be placed pretty much anywhere, as it can only be called once the page has loaded, anyway. Is your problem that you can't change the head of the page (to include that function) for some reason? In any case, go ahead and put it in the body.

brian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux