jeudi 2 avril 2015

how to pass checkbox value(checked/unchecked) to controller as href parameter in jsp

I am a beginner in jsp.I want to get data from database and show checked on a checkbox depending on db value i.e. 0 or 1.This is working for me.But I also want o that when I check or uncheck the checkbox it will reset value and pass it to controller as a href parameter. here is my jsp:



<%@ taglib uri="http://ift.tt/QfKAz6" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Investor Account</title>
</head>

<body>

<script type="text/JavaScript">
function updateCheck(){

if(document.getElementById('chk').checked){
document.getElementById('chk').value = 1;
location.href=""
alert(document.getElementById('chk').value);



}
else{
document.getElementById('chk').value = 0;
alert(document.getElementById('chk').value);


}

}

</script>
<div align="center">
<h1>Investor Account List</h1>

<table border="1">
<th>ID</th>
<th>Investor Code</th>
<th>Investor Name</th>
<th>SMS Subscriber</th>
<th>Action</th>
<c:forEach var="investorAcc" items="${listInvestorAcc}" varStatus="st">
<tr>
<td>${st.index + 1}</td>
<td>${investorAcc.investor_code}</td>
<td>${investorAcc.investor_name}</td>
<td> <input type="checkbox" id="chk" name="chkSms" value= <c:if test="${investorAcc.sms_sub==1}">1</c:if> onclick="updateCheck();"
<c:if test="${investorAcc.sms_sub==1}">checked="checked"</c:if>/>

<td>

<a href="updateInvestorAcc?id=${investorAcc.id}&chkSms=<c:if test="${chkSms==1}">1</c:if>"> Update </a>
</td>

</tr>

</c:forEach>
</table>
</div>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire