Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java variable as argument in javascript function  RSS feed

 
Arundhathi Menon
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How do i acess a java variable as a javascript functions argument???
My7 code is

<html:text property="startTime" size="9" onfocus="StartDisplay(this.form,'<%=b%>')"...

I need to pass b which is an integer..

if i put b..error- b is undefined
if i put 'b'...error-it takes b as the argument
if i put '<%=b%>' ...it takes thgat string

Pls tell me what to do
regards
Menon
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah gettin a string is OK. parse it as int inside javascript function.
 
Sheldon Fernandes
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arundhathi,

How do i acess a java variable as a javascript functions argument???

The question is not very well worded. What you are doing is dynamically generating html content which includes javascript.

To understand the reason you are getting the behaviour that you have observed, you need to understand what values can be passed to attributes of tag libraries. In this case, the onfocus attribute has "rtexprvalue" set to true. You can see this in the struts-html.tld as
<attribute>
<name>onfocus</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
OR
in the <html:text> documentation as (RT EXPR).

What this means is that the value of this attribute can be one of 2 things:
- JSP expression
- static values
Since in your case the value is dynamic, it needs to be a JSP expression.

You can try this.
<% String focusHandler = "StartDisplay(this.form," + b + ")"; %>
<html:text property="startTime" size="9" onfocus="<%=focusHandler%>" />

For more information on tab libraries click here.

Hope this helps.
Sheldon

----------
Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for life.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!