How do I display a JavaScript variable inside my HTML tags in JSP? -
i have function gets original string , slice it. how display results in html?
function parsingfunction() { var originalstring = entity.getgenresolr(); var results = originalstring.slice(1, -1); return results; } </script> <div class = "option_title_summary_summary"> <p>genre list: ${parsingfunction}</p>
well code using incorrect because can't update html
javascript
variables way, have update html
javascript
instead.
your code this:
function parsingfunction() { /*var originalstring = entity.getgenresolr(); var results = originalstring.slice(1, -1); return results;*/ return ["aaa", "bbb", "ccc"].join(" -- "); } document.getelementbyid("genrelist").textcontent = "genre list: " + parsingfunction();
<div class="option_title_summary_summary"> <p id="genrelist"> </p>
i commented old code avoid exceptions undefined
variables , gave id="genrelist"
paragraph can in js code.
note:
there's solution it's not recommended in javascript, using document.write()
:
<script> function parsingfunction() { /*var originalstring = entity.getgenresolr(); var results = originalstring.slice(1, -1); return results;*/ return ["aaa", "bbb", "ccc"].join(" -- "); } </script> <div class="option_title_summary_summary"> <script> document.write('<p> genre list: ' + parsingfunction() + '</p>'); </script>
Comments
Post a Comment