I have a javascript function to create a record called createSancion
, it verifies the fields and then shows a message to confirm the saved, if it is accepted it becomes a form.submit
It happens that you add another script to count the data of a checkbox at the end of the record, called verify . and I've tried to set it up to count and then save, but I could not.
I would like that when you give the save button you run the function of creating the record but before showing "you want to save the data" I will verify the checbox, and once verified it says "you want to save the data?"
Try doing it by entering the check function within the creation, but when it verifies after executing it does nothing else.
Also try to place both function calls on the button, but just run the first one you have.
Here I leave the codes:
createSancion ():
function CrearSancion()
{
var obj1 = window.document.getElementById("cedula");
var obj2 = window.document.getElementById("cedula1");
var obj3 = window.document.getElementById("cedula2");
var obj4 = window.document.getElementById("narticulo");
var obj5 = window.document.getElementById("naparte");
var obj7 = window.document.getElementById("unidad");
var obj8 = window.document.getElementById("unidad_uuss");
var obj9 = window.document.getElementById("estados");
var obj10 = window.document.getElementById("docanexos");
var obj11 = window.document.getElementById("fecha_ultimo");
var obj12 = window.document.getElementById("cargo");
var obj13 = window.document.getElementById("xdes_sancion");
var obj14 = window.document.getElementById("fecha_inicio");
var obj15 = window.document.getElementById("aclaratoria");
var obj16 = window.document.getElementById("nombrecompleto1");
var obj17 = window.document.getElementById("nombrecompleto2");
var obj18 = window.document.getElementById("nombrecompleto3");
if(obj1.value == "")
{
alert ("Debe agregar el numero de cedula del sancionado");
}
else if((obj16.value == ""))
{
alert ("Debe ingresar el nombre del sancionado");
}
else if((obj17.value == ""))
{
alert ("Debe ingresar el nombre del sancionado");
}
else if((obj18.value == ""))
{
alert ("Debe ingresar el nombre del sancionado");
}
else if((obj2.value == ""))
{
alert ("Debe agregar el numero de cedula del que sanciona");
}
else if((obj4.value == "0"))
{
alert ("Debe agregar el articulo");
}
else if((obj5.value == "0"))
{
alert ("Debe agregar el aparte del articulo");
}
else if((obj9.value == "0"))
{
alert ("Debe seleccionar el lugar donde se realiza la sancion");
}
else if((obj10.value == "0"))
{
alert ("Debe seleccionar el tipo de documento anexado a la sancion");
}
else if((obj11.value == ""))
{
alert ("Debe agregar la fecha del ultimo ascenso");
}
else if((obj12.value == ""))
{
alert ("Debe agregar el cargo");
}
else if((obj13.value == "0"))
{
alert ("Debe agregar el tipo de sancion");
}
else if((obj14.value == ""))
{
alert ("Debe agregar la fecha de inicio de la sancion");
}
else if((obj15.value == ""))
{
alert ("Debe agregar la aclaratoria de la sancion");
}
else
{
if(confirm('Esta seguro que desea guardar los datos'))
{
var obj1 = window.document.getElementById('accion');
obj1.value = 'I';
form1.submit();
}
}
}
verify ():
function verificar(){
alert("Verificando sus datos Selección de Circunstancias Atenuantes");
var cb = [];
var atenuantes="atenuantes[]";
var n1=0,cuales="";
cb = document.getElementsByName(atenuantes);
for (var i = 0; i < cb.length; i++){
var e = parseInt(i);
if(cb[i].checked == true){
cuales += cb[i].value + ' ';
n1++;
}
} // fin loop
if(n1 == 0){
var mensaje1 = 'No hubo selección de atenuantes';
}else{
var mensaje1 = 'Se marcaron el/las opción(es) de valor(es): ' + cuales
}
alert('El total de opciones marcadas es: ' + n1);
alert(mensaje1);
alert("Verificando sus datos Selección de Circunstancias Agravantes");
var cb2 = [];
var agravantes="agravantes[]";
var n2=0,cuales2="";
cb2 = document.getElementsByName(agravantes);
for (var i = 0; i < cb2.length; i++){
var e = parseInt(i);
if(cb2[i].checked == true){
cuales2 += cb2[i].value + ' ';
n2++;
}
} // fin loop
if(n2 == 0){
var mensaje2 = 'No hubo selección de agravantes';
}else{
var mensaje2 = 'Se marcaron el/las opción(es) de valor(es): ' + cuales2
}
alert('El total de opciones marcadas es: ' + n2);
alert(mensaje2);
document.getElementById('boxes').reset();
}
html button:
<input type="button" name="crear" onClick="CrearSancion();" value="Aceptar" />
I put it at the end, since it shows 4 messages and it would be cumbersome to show the 4 messages every time you lack a value