My intention is that when clicking on a button, an alert appears with the option Confirm or Cancel, and that in case of Confirm, the forwarding process is carried out as if it did not have the label onclick
. I have the following code written in a jsp:
<spring:url value="/vendedores/eliminarArticulo/{articuloId}" var="eliminarArticuloUrl">
<spring:param name="articuloId" value="${articulo.id}"/>
</spring:url>
<a href="${fn:escapeXml(eliminarArticuloUrl)}">
<button onclick="alerta()" class="btn btn-default" type="submit">Dar de baja</button>
</a>
And the function in JavaScript:
function alerta() {
var opcion = confirm("¿Seguro que desea dar de baja el artículo?");
if (opcion) {
}
}
The question is, what should I put in if
it so that when Accepting directly it does the function of button
, that is, if Accepts directly, it calls href
which in this case would be /vendedores/eliminarArticulo/{articuloId}
, articleId being a parameter that is taken from a variable that receives the page.
If what you want is that, in case of confirmation by the user, the button has the default behavior, you just have to return the value returned by prompt to the onclick event: