Reputation: 5816
I have below CheckBox in JSP file
<input type="checkbox" name="vehicle" value="Bike"
onclick="javascript:selectCustomers(${sessionScope.custId});">
Getting the following error:
org.apache.jasper.JasperException: customer.jsp(1419,33) According to TLD or attribute directive in tag file,
attribute onclick does not accept any expressions
Can we not use expression language in JavaScript (in my case under onClick()
Event)?
Upvotes: 2
Views: 15241
Reputation: 46841
When a JSP page is called, the following happens, in this order:
So, your statement: ${sessionScope.custId}
is executed before the the HTML is sent to the user, and the input of selectCustomers()
function is already set to before calling it.
For more info have a look at my another post JSP inside ListItems onclick
Right click in the browser and look at the view source.
Try below sample code that might help you.
Enclose ${...}
inside the single quotes.
<c:set var="custId" value="1234" scope="session" />
Before :
<c:out value="${sessionScope.custId}"></c:out>
<input type="checkbox" name="vehicle" value="Bike"
onclick="javascript:selectCustomers('${sessionScope.custId}');">
<c:set var="custId" value="4321" scope="session" />
After:
<c:out value="${sessionScope.custId}"></c:out>
View Source code: (Right click in browser to view it)
Before : 1234
<input type="checkbox" name="vehicle" value="Bike"
onclick="javascript:selectCustomers('1234');">
After: 4321
Upvotes: 3
Reputation: 2774
Try this:
<input type="hidden" id="custId" name="custId" value="${sessionScope.custId}">
<input type="checkbox" name="vehicle" value="Bike" onclick="javascript:selectCustomers();">
function selectCustomers(){
var custId = document.getElementById('custId').value;
}
Upvotes: 1