I have a form in which I need to know which button I clicked, to get the id
, and so with the id
delete a row in a BD, the problem I have in how to get the id
of the button . I put all the code that influences:
<form class="form-horizontal" action="Propietario" method="post">
<input type="hidden" name="ajax" value="" />
<input type="hidden" name="accion" value="modRatios" />
<table id="ratios" class="display dataTable no-footer">
<thead>
<tr>
<th><span class="texto" data-i18n="panelcontrol.propietario.precios.horas">...</span></th>
<th><span class="texto" data-i18n="panelcontrol.propietario.precios.preciomax">...</span></th>
<th></th>
</tr>
</thead>
<tbody>
<c:forEach items="${sessionScope.propietarioRatios}" var="ratios" varStatus="myIndex">
<tr>
<td><input type="text" name="horas${myIndex.index + 1}" value="<c:out value="${ratios.horasRD}" />" style="margin:1em auto;" required></td>
<td><input type="text" name="precioMax${myIndex.index + 1}" value="<c:out value="${ratios.descuentoRD}" />" style="margin:1em auto;" required></td>
<td><button class="btn btnaction btnamarillo" name="accion" value="borrarRatios" id="ratio${ratios.idratio}" type="button"><span class="glyphicon glyphicon-remove"></span></button> </td>//Este es el button en cuestion!!!
</tr>
</c:forEach>
</tbody>
<tfoot>
<tr>
<td><button class="btn btnaction" id="add" type="button"><span class="texto" data-i18n="panelcontrol.propietario.precios.añadir">...</span><span class="glyphicon glyphicon-plus"></span></button></td>
<td><button class="btn btnaction btnamarillo" type="submit" id="precioRat"><span class="texto" data-i18n="panelcontrol.propietario.precios.guardar">...</span><span class="glyphicon glyphicon-floppy-disk"></span></button></td>
<td></td>
</tr>
</tfoot>
</table>
This is the form, the c:forEach
draws rows depending on the data in the database, which can be 1 or several, on the button, the ids, are ratio1 , ratio2 , ratio10 ...
if(vAccion!=null){
switch(vAccion){
case "misusos":
cargarmisusuos(request, response, base);
break;
case "ocupacion":
cargarocupacion(request, response, base);
break;
case "plazas":
cargarplazas(request, response, base);
break;
case "plazaactivar":
activarplaza(request, response, base);
break;
case"plazasmultiple":
activarplazamultiple(request, response, base);
break;
case "facturas":
cargarfacturas(request, response, base);
break;
case "generarfacturas":
generarfactura(request, response, base);
break;
case "descargarfactura":
descargarfactura(request, response, base);
respuestapordefecto = false;
break;
case "precios":
cargarratios(request, response, base);
cargarcomunidades(request, response, base);
break;
case "modCoeficiente":
modificarCoeficiente(request, response, base);
break;
case "modRatios":
modificarRatios(request, response, base);
break;
case "borrarRatios":
borrarRatios(request,response,base);
break;
default:
request.setAttribute("errorpanelcontrol", "propietarioaccionnopermitida");
break;
}
}
private void borrarRatios (HttpServletRequest request, HttpServletResponse response, BaseWeb base){
//Establecemos la navegacion activa en la sesión
HttpSession session = request.getSession();
PanelControlNav pcnav = (PanelControlNav)session.getAttribute("PanelControlNav");
pcnav.setNavActivo("propietario");
pcnav.setTabActivo("propietario", "propprecios");
session.setAttribute("PanelControlNav", pcnav);
PropietarioWebControler.borrarRatios(request, response, base);
}
That switch
, depends on the button that you press send to one method or another, but of course if I have 10 delete buttons, it will go to the same method, but it does not pass the id
or anything.
public static void borrarRatios (HttpServletRequest request, HttpServletResponse response, BaseWeb base){
HttpSession session = request.getSession();
RatioDescuentoControlador ratContr = new RatioDescuentoControlador(base.getVariablesGlobales());
try{
}catch(Exception ex){
base.getLoggerGarageScanner().error("Se ha producido un error");
request.setAttribute("errorpanelcontrol", "propietariocomunidaderrorcarga");
}
finally{
}
}
And this is the method where I have to delete the rows of the BD. (that's already done)