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

Community
  • 1
  • 1
Java Questions
  • 7,624
  • 38
  • 114
  • 172

2 Answers2

4

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>
Shiv Kumar Ganesh
  • 3,731
  • 8
  • 43
  • 79
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 
});
Shades88
  • 7,398
  • 21
  • 80
  • 126
  • 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 – Java Questions Sep 17 '12 at 10:30