Jump to content

onload event for other than body element


ankur0101
Go to solution Solved by 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>
Link to comment
Share on other sites

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

Link to comment
Share on other sites

I tried to do

 

 

$(windows).load(function () {
alert('hi);
myFunc(str);
});
 
and 
 
document.onload=function{
alert('hi');
};
 
 
I know this is simple thing but god knows its not working
Edited by ankur0101
Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

  • Solution

Problem solved, I left --> }); after writing myFunc()

Things are working as I wanted.

 

Thanks for your help trq regarding jquery ready. I am bad at java script n jquery.

Edited by ankur0101
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.