how to call a function of javascript in jsp without any event
14,789
If I understand you correctly, then you could use the onload event. Look at
http://www.javascriptkit.com/javatutors/event3.shtml
window.onload vs <body onload=""/>
Author by
Admin
Updated on June 15, 2022Comments
-
Admin almost 2 years
How can i call a javascript function without any event. I have a session variable namely x. what I need is to call a javascript function demo() if the session variable is not null.
<% if((String)session.getAttribute("x")!=null) { %> <script type="text/javascript"> demo(); </script> <% } %>
let me know the right way of calling the demo function.
-
Admin over 10 yearsThanks for the response but if I use the onload event then it'll get executed even if the session variable isn't set which i don't want to happen. I want it to call it without any event.
-
rickz over 10 yearsI was thinking that you could use the same conditional code that you posted. If the session variable is not null, then add the body tag with the onload attribute and your JavaScript function to the response. If the session variable is null then add a plain body tag to the response. By the way, you should use JSTL to do this.