I have the following JSP code:
<c:forEach items="${requestScope.XX}" var="x">
<tr>
<td><input type="radio" value="${x.xID}" name="x"></td>
<td> ${x.name}</td>
</tr>
</c:forEach>
Whenever the user clicks on radio button, I need to take both x.xID and ‘x.name’ and validate in Javascript.
How do I pass the the selected value to Javascript?
I tried with onClick function, but the value is not getting passed to Javascript.
function validate(y) {
alert(y.value);
}
I’m guessing that you are a bit confused about server-side (JSP) and client-side (JavaScript) code execution, but anyway:
Edit: added single quotes for error-proofing.
Edit 2: as I’d guessed, you are a bit confused about where JavaScript is executed: it runs on the client, where the objects you had in JSP do not exist, and as such
y.valueis meaningless invalidate(). Your function should be something like this: