Search code examples
javajspjstljstl-functions

jstl c:set is not working on js code in jsp file


I have a JSON from a service. I am appending a html block by JSON value and I have to check some values for appropriate display. I am trying to set discountValue variable but it not working with js variable. How can I solve it?

  if (data!="")
                {
                    $.each(data,function(index,element){
                        var intDiscount=parseInt(10);
                        console.log("intDiscount::"+intDiscount);

                        var strIndex='';
                        strIndex+='<div class="card">';
                        strIndex+='<c:set var="discountValue" value="'+intDiscount+'"/>';
                        console.log("${discountValue}");
...
...
...
...
                 }
                 $('#visilabs-FavouriteCategoryTopSeller').append(strIndex);

Console log:

intDiscount::10
0

Solution

  • I have solved it with using if condition with js:

    if(element.discount>0){
                                strIndex+=                      '           <span class="label label-danger discount">'+'%&nbsp;'+intDiscount+'</span>';
                            }
    

    Thanks everyone