I write the following code in simulate.jsp , to receive some String “simulationInfos” from the Server:
<s:property id="simulationInfos" value="simulationInfos" /><br/>
When simulate.jsp has been returned, I can see, that the String simulationInfos existing.
My Question is: How can I pass simulationsInfos to java script?
I tried the following:
<script type="text/javascript">
var data=document.getElementById("simulationInfos").value;
console.log("data is: ", data);
And with jQuery:
var data=$("#simulationInfos").val();
</script>
and I get the following Error in Firebug: Uncaught TypeError: Cannot read property ‘value’ of null
How can I pass some struts 2 variable to javascript?
First, you should take a look to the HTML code that the JSP is generating. It can explain why you cannot retrieve the value. Then, maybe you will see that you need some extra HTML code. For example:
And in you script:
If you take a look to the property tag doc, you can see that there is not any “id” parameter.
Edition: JS correction.