Wrong value in Javascript function param

By | July 17, 2018
Questions:

I’m iterating over a list of object in c:foreach loop and creating a call to a javascript function that complete the length of my var an call server:

<c:forEach items="${clientList}" var="cli" varStatus="index">
...
<a href="javascript:goToClientDetail(${cli.client.PK})">                                
     <img src="<%=imagesPath%>search.gif"  width="14" height="14" border="0" align="absmiddle"/>
</a>

If I show ${cli.client.PK} in my .jsp I can see the correct value, but the problem is that the javascript function is getting a wrong value.

My JS function:

<script language="javascript">
function goToClientDetail(pk){
    alert(pk);
    var res = pk.toString();
    while(res.length < 12){
        res = '0'.concat(res);
    }
    document.getElementById('idlocalClient').value=res;
    document.getElementById('fClientDetail').submit();
}

alert(pk) shows different value that ${cli.client.PK} in the .jsp

Any hint?

Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *