简体   繁体   中英

How to set the JSTL variable value through javascript variable

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>";

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

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>;

Set to jstl variable value using javascript

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM