• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to pass integer into the javascript using struts html tags. I am able to pass String but not int  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am new to Struts framework. I have a simple requirement, in which I need to pass one interger value in the javascript. Which I have defined in the jsp only <%int itrcount = 0 %>, which will increment in loop. In below part of the jsp I have one <html:select> tag and I need to pass this itrcount in javascript method getValues. I am able to pass this same varibale if I used Input tag using scriptlet. but not with

Struts tag i.e. <html:select onclick="getValue(<%=itrcount%>)" >

Please help me in this regard.
 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javascript treats all variables as strings, unless specifically instructed. You need to change your code from :

<html:select onclick="getValue(<%=itrcount%>)" >

to

<html:select onclick="getValue(eval(<%=itrcount%>))" >

to get the desired result. FYI, eval() is a built-in javascript method which will convert the numeric strings to numerics.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not remotely correct: <%= ... %> outputs the string representation of the value. The string representation of an int is an int. getValue(5) is valid JavaScript.

The first thing to check is to see if the HTML is being rendered correctly: does the onclick attribute value render correctly? If not, then there's an issue accessing the script variable (which are almost bad and unnecessary). Showing more of the surrounding code would help us provide alternative solutions.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!