You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fea jabi <zy...@hotmail.com> on 2005/12/14 16:17:39 UTC

struts and javascript

In my JSP, have to use the defined variable in javascript. How can I use it?

The below code is returning a null obj for totalObj in the javascript.

.............
........................
<script>
.........
var totalObj = document.getElementById("total");
totalObj=Number(obj1) + Number(obj2);

</script>
.....................
.....................
<bean:define id="total"><bean:write name="Form1" 
property="total"/></bean:define>
................
.........

thanks.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[OT] Re: struts and javascript

Posted by Dave Newton <ne...@pingsite.com>.
fea jabi wrote:

> In my JSP, have to use the defined variable in javascript. How can I 
> use it?
> var totalObj = document.getElementById("total");

Wow, that's so far off I'm not even sure where to start. Marked OT 
because this has more to do with a fundamental misunderstanding of how 
webapps work than anything struts-ish.

JavaScript is run client-side, Struts tags (or any other, for that 
matter) are run server-side. This sounds familiar; did we have a go at 
this once before?

You _could_ do something like (syntax probably wrong; working with other 
technology today):

var total = <c:out value='${total.intValue}'/>;
total += whatever;

and then reference 'total' with a javascript chunk or via any number of 
element replacement techniques on the page.

Does that help?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org