Click to See Complete Forum and Search --> : calling javascript from HTML <Body> without any event


Avneesh
05-08-2003, 04:32 AM
How can I call a javascript from HTML <Body> without any event.

Thanx

Charles
05-08-2003, 04:42 AM
You cannot. But why would you want to?

Avneesh
05-08-2003, 04:46 AM
Hi Charles,

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.

Can u help me in this???

Regards

nkaisare
05-08-2003, 03:43 PM
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.

You can <body onload> and within the javascript check for the value of that variable/parameter.

Avneesh
05-09-2003, 03:07 AM
Hi nkaisare,

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.

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.
hope this would explain u my situation.

Regards
Avneesh

nkaisare
05-09-2003, 07:24 AM
Can you do something like this in your server side script:
if (foo == 10) {
print ('<body onload="javascript_that_runs_when_foo_is_10">'); }
(Of course if you could do that, you'd probably do it from the script itself)

Alternatively, I dont find any difference between the following

<head>
<script type="text/css" makeactive="if (foo==10)">
// javascript
</script>
</head>



<head>
<script type="text/css">
...
if (foo==10)
...
</script>
<body onload="checkfoo()">


If there is more concrete example, someone may be able to help better.

- Niket

Vladdy
05-09-2003, 08:45 AM
You have to consider this chain of events:
- Server side code is executed generating html output
- The page is delivered to the client and rendered
- 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)

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: http://forums.webdeveloper.com/showthread.php?s=&threadid=5810