2

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.

Shubham Middha
  • 33
  • 1
  • 2
  • 5

1 Answers1

0

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=""/>

Community
  • 1
  • 1
rickz
  • 4,324
  • 2
  • 19
  • 30
  • Thanks 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. – Shubham Middha Aug 08 '13 at 04:25
  • I 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. – rickz Aug 08 '13 at 15:57