2

Possible Duplicate:
Javascript that executes after page load

how to call a javascript method as soon as page is loaded.

i have a java script which needs to be called soon after the jsp page is loaded, how to achieve this in javascript.

could any one of you help me pelase.

Regards

1

2 Answers 2

3

You can write a code snippet something like this :-

window.onload(function(){
//Your JavaScript here
});

And if using JQuery then

document.ready(function(){
//Your JavaScript Here
});

Or you can have all your JS after all the HTML.

you can even use a function called :--

document.onload(function(){
//Your code Here
});

Last but not the least you could even try out this

 <body onload="YourJSMethod();">
        <!-- Some html content -->
    </body>
Sign up to request clarification or add additional context in comments.

2 Comments

With JQuery you can shorten it to $(function () { [your code] });
window.onload(function(){}); is incorrect. addEventListener is preferred.
2

you can try

<body onload="someMethod();">
    <!-- Some html content -->
</body>

This will call your method as soon as body tag of your page is loaded. Alternatively you can make use of jquery's document ready function.

$(document).ready(function() { 
    // your code 
});

1 Comment

i have few methods which loads the value for few combo box through java code, and than set values for loaded combo box once the apge is loaded

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.