Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  74] [ 1]  / answers: 1 / hits: 18997  / 11 Years ago, fri, august 2, 2013, 12:00:00

Hi I've the following code in jsp. I am trying to pass the value to javascript as follows. But it is not working.The code is as follows:



    <td><button name = btn onclick=callMe(<c:out value='${bus.vehicleId}'/>)>Show Details</button></td>


(Vehicle id is printing if I use in my jsp.) Javascript is like this.



    function callMe(myId) {
alert(myId);}


Here I am getting value as undefined. I've tried in different way as follows



    <td><button name = btn onclick=callMe('${bus.vehicleId}')>Show tails</button></td>


This is also not working.Please help me asap.


More From » jsp

 Answers
5

Your vehicleID might be string. If so, Yes! you get always undefined as a result. What ever the values coming as a result of <c:out value='${bus.vehicleId}'/> will be treated as a variable in html and javascript trying to print that variable value, which is undefined.



Try this way to let java script treat that jstl value as string literal



onclick=callMe('${bus.vehicleId}')>


Find single colon and double colons positions!


[#76573] Thursday, August 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daytonm

Total Points: 519
Total Questions: 83
Total Answers: 89

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;