java - How to add javascript handler to button? -
i have button on jsp form must send boolean value controller.
<button type="button" class="btn btn-success"><i class="glyphicon glyphicon-ok-circle"></i> activate</button>
on form i'm using pojo object have status (boolean status).
public class user implements serializable { private string name; private boolean status; // getters , setters omitted }
i need add javascript handler button send status , user id controller post method. how can using javascript?
upd:
<c:foreach items="${users}" var="user"> <tr> <td>${user.id}</td> <td>${user.name}</td> <td>${user.email}</td> <td>${user.country}</td> <td class="col-sm-1 col-md-1"> <a href="/user/${user.id}" style="text-decoration: none"> <button type="button" class="btn btn-primary btn-block"><i class="glyphicon glyphicon-pencil"></i> edit </button> </a> </td> <c:choose> <c:when test="${user.active == true}"> <td class="col-sm-1 col-md-1"> <button type="button" class="btn btn-danger btn-block"><i class="glyphicon glyphicon-remove"></i> suspend </button> </td> </c:when> <c:otherwise> <td class="col-sm-1 col-md-1"> <button type="button" class="btn btn-success"><i class="glyphicon glyphicon-ok-circle"></i> activate </button> </td> </c:otherwise> </c:choose> </tr> </c:foreach>
you can use as:
function dosend(){ document.forms[0].action = "url?val=true"; document.forms[0].submit(); }
and
<button type="button" onclick="dosend()" , other attrubute>
specify method attribute on form.
<form name="myform" method="post">
it cause form submitted post.
or can using hidden field as:
<html> <head> <script type="text/javascript"> function dosend(){ alert("hi"); document.forms[0].setattribute("method","post"); document.forms[0].submit(); } </script> </head> <body> <form action="test2.html" method="get"> <input type="hidden" name="hiddenfield" value="ture1"/> <input type="button" onclick="dosend()" value="click"/> </form> </body> </html>
Comments
Post a Comment