1

I would like to display html code when the user clicks on a particular box.

When the user selects a value from one of the available options, a JavaScript function is invoked which stores the selected value against a variable.

I am having difficulty with implementing code to compare the value of EL variable with the innerHTML variable.

Below is the code I am currently using:

var groupid = parseInt($('#selectgroup').val());    

document.getElementById("facilityTable").innerHTML= "<c:forEach var='group' 

items='${groups}'>"+
"<c:if test='${group.key == (groupid)}'>"+

"<td>+Test+${group.value.groupName}</td>"+

"<td>${group.value.groupId}</td>" +                                                                                     

"</c:if>"+

"</c:forEach>";
0

2 Answers 2

0

Your JSTL tags will not be a part of JS output, so there is not reason to put them into quotes, e.g.:

document.getElementById("facilityTable").innerHTML= ""
<c:forEach var='group' items='${groups}'>
  <c:if test='${group.key == (groupid)}'>
+ "<td>+Test+${group.value.groupName}</td>"+
"<td>${group.value.groupId}</td>"                                                                                     
  </c:if>
</c:forEach>;
Sign up to request clarification or add additional context in comments.

3 Comments

but can,t get groupid vaule in <c:if test='${group.key == (groupid)}'>.
groupid variable is declare in javascript var groupid = $('#selectgroup').val();
You can not use JS variables in JSTL EL expressions, because they are executed on the server before user gets result Html and JS starts execution. You can use JSTL to render groups as JS array. And then iterate through it using simple JS for loop.
-2

Set to jstl variable value using javascript

<script>
    function function1()
    { 
        <c:set var="temp" value=""/>
        temp="Hello";
        alert(temp);   
    }
</script>

1 Comment

There is no connection between the JSTL variable temp and the global JS variable temp here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.