I'm currently using PHP and AJAX to create a basic CRUD system. I want to display a form with three buttons: Grabar, Modificar, and Eliminar. The issue I'm facing is determining the action to take based on which button is clicked. For instance, clicking the Grabar button should redirect to registro.php, clicking Modificar should redirect to modificar.php, and the same logic applies to the Eliminar button redirecting to eliminar.php.
How can I achieve this functionality in JavaScript? This is what I have so far:
function enviarDatosEmpleado(){
//div where the results will be displayed
divResultado = document.getElementById('resultado');
//collecting input values
nom=document.nuevo_empleado.nombre.value;
ape=document.nuevo_empleado.apellido.value;
web=document.nuevo_empleado.web.value;
valor=document.nuevo_empleado.Submit.value;
alert(valor);
}
/*
ajax=objetoAjax();
ajax.open("POST", "registro.php",true); */
And here is my form:
<form name="nuevo_empleado" action="" onsubmit="enviarDatosEmpleado(); return false">
<h2>New employee</h2>
<table>
<tr>
<td>Names</td><td><label><input name="nombre" type="text" /></label></td>
</tr>
<tr>
<td>Last Name</td><td><label><input type="text" name="apellido"></label></td>
</tr>
<tr>
<td>Website</td><td><label><input name="web" type="text" /></label></td>
</tr>
<tr>
<td> </td><td><label><input type="submit" name="Submit" value="Grabar" /></label></td>
<td><label><input type="submit" name="submit" value="Modificar" /></label></td>
<td><label><input type="submit" name="submit" value="Eliminar" /></label>
</td>
</tr>
</table>
</form>
Can you also assist me with writing the if statement for this functionality?