I have one in jsp page.
i want to pass this value as argument of java script function call
my jsp apge code is:
<input type="submit" onclick="play(<s:property value="vname"/>)">
my java script function code:
function play(n)
{
alert(n);
}
please help me to solve this problem;
regard
Rohit kachhadiya
I have one in jsp page.
i want to pass this value as argument of java script function call
my jsp apge code is:
<input type="submit" onclick="play(<s:property value="vname"/>)">
my java script function code:
function play(n)
{
alert(n);
}
please help me to solve this problem;
regard
Rohit kachhadiya
Share Improve this question asked Sep 20, 2012 at 7:23 Rohit R.K.Rohit R.K. 2972 gold badges4 silver badges14 bronze badges3 Answers
Reset to default 1You have to wrap struts tags with quotes:
<input type="submit" onclick="play('<s:property value="vname"/>')">
otherwise the value of "vname" will be interpreted as a JavaScript variable, not a string!
Using struts2 tag:
<s:submit onclick="javascript:play('%{vname}')" />
Agree with daveoncode, apart from that In your js, get it directly like
var varName = document.forms[0].name/id.value;
Or you have one more option to write inline js and pass value of your element. But its a bad practice.