calling javascript from HTML <Body> without any event

How can I call a javascript from HTML <Body> without any event.<br />
<br />
Thanx<!--content-->You cannot. But why would you want to?<!--content-->Hi Charles,<br />
<br />
I want to call a javascript function through my JSP page when a server side variable reaches a perticular value.Here no client event is actually involved.This Should happen from HTML body only.<br />
<br />
Can u help me in this???<br />
<br />
Regards<!--content-->Can't you handle this with jsp itself? If a server-side event needs to trigger a function, why would you need a client-side javascript.<br />
<br />
You can <body onload> and within the javascript check for the value of that variable/parameter.<!--content-->Hi nkaisare,<br />
<br />
I can handle this thing from JSP itself but then i have to submit the page again. That will be a certain waistage of time.<br />
<br />
I give u a practical example. suppose my javascript function has just an alert("Hello") in it, I want to call this when a server side variable reaches a perticular value ...... now I if have to call the javascript function I have to submit the page and come back to javascript bu <body onload>.This is the thing which i don't want. I want to call the javascript function as and when server side variable reaches a pericular value without submitting the page again.<br />
hope this would explain u my situation.<br />
<br />
Regards<br />
Avneesh<!--content-->Can you do something like this in your server side script:<br />
if (foo == 10) {<br />
print ('<body onload="javascript_that_runs_when_foo_is_10">'); }<br />
(Of course if you could do that, you'd probably do it from the script itself)<br />
<br />
Alternatively, I dont find any difference between the following<br />
<br />
<head><br />
<script type="text/css" makeactive="if (foo==10)"><br />
// javascript<br />
</script><br />
</head><br />
<br />
<br />
<br />
<head><br />
<script type="text/css"><br />
...<br />
if (foo==10)<br />
...<br />
</script><br />
<body onload="checkfoo()"><br />
<br />
<br />
If there is more concrete example, someone may be able to help better.<br />
<br />
- Niket<!--content-->You have to consider this chain of events:<br />
- Server side code is executed generating html output<br />
- The page is delivered to the client and rendered<br />
- Your javascript starts execution (I mean you can execute it during rendering, but that is still after your server side code is done with that part)<br />
<br />
You can not "wait" for a server variable to become something all within one page. You have to load the page and then check in with the server every so often. See this thread: <!-- m --><a class="postlink" href="http://forums.webdeveloper.com/showthread.php?s=&threadid=5810">http://forums.webdeveloper.com/showthre ... eadid=5810</a><!-- m --><!--content-->
 
Back
Top