java - JSP set javascript variable without hidden input -
i'm looking better way set javascript variable in jsp. not hidden inputs transfer data javascript. there better solution can think of?
currently on project, javascript variables handled via jsp in fashion:
<input id="javavalue" type="number" value="${java_variable}" class="hidden">
where in javascript (jquery) following:
var valuefromserver = $("#javavalue").val();
however, feel approach kinda... inelegant. causes problem way project handles 508 compliance, wave pick on these fields, , developers required add labels them. i'm looking better way. i'm aware of setting variables in own mini script tag so:
<script> value=${java_variable} </script>
are there drawbacks i'm not seeing approach? seems cleanest , most-simple solution.
i'm aware can set them directly on model , grabbing using jquery. seems better approach option 1, there limitations or problems arise type of approach?:
<span id="javavalue" data-value=${java_variable}>
does else have ideas/opinions on these approaches?
you set global variable directly below.
<script> var date = '<%= new date().tostring() %>'; console.log(date); <script>
Comments
Post a Comment