Jump to content

onload event for other than body element


ankur0101

Recommended Posts

Hi,

I have following code >


<select name="type">
            <option value="all">All</option>
            <option value="act" selected="">Active</option>
            <option value="res">Re-signed</option>
            </select>

Is there any way I can add onload event to <select> ?

onload is only available for <body>. I am using MVC architecture in PHP. My <body> is located in header.php so I cannot use onload in <body>.

What I want to have is when a page loads, my java script function will automatically execute. It would be fine if I put event in any other tag such as <p>

Does not work.

My function is myFunc(str) and I write as follows :

 

 

<script>
$(document).ready(function () {
myFunc();
});
</script>
 
This didnt work so I added parameter i.e. str
<script>
$(document).ready(function () {
myFunc(str);
});
</script>
 
Here is how my page looks like
 
 
<script>

    	function myFunc(str) {
		 ...
                 ...
</script>

<script>
	$(document).ready(function () {
	myFunc(str);
	});
</script>

It does not work at all

I came to know why it is not working. As I said earlier, I am using MVC (Codeigniter here)

 

In Header.php,

I am loading calling css and js files along jquery main file.

 

In mainbody.php, 

I am writing myFunc() and calling that read jquery code.

 

This is why it is not working. I wrote .ready() thing that you said in header.php and it worked fine.

 

Now problem is I dont want to write that in header.php because it is common to all pages. And myFunc() is only called on maonbody.php.This is why I want to write jquery outside <head> i.e. in <body>

If jquery does not work, how can I do with java script ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.