I have two checkbox groups that are filled with database and I have a javascript function that deletes them when a radiobutton is changed (there is a radio button to show each group of checkbox), I think they are causing problems because I can not even make an alert within the system, although some javascript functions do work, for example the limit of checkbox, but when wanting to execute inside the form other javascript do not work.
what can it be?
function and limit of checkbox (Functioning - SIN ALERT)
function validacionMaximo(input) {
limite=3;
seleccionados=0;
if (input.checked) {
for (i=0; ele=input.form.elements[i]; i++)
if (ele.checked) seleccionados++;
if (seleccionados>limite){
alert("No puede seleccionar mas de dos elementos");
input.checked=false;
}
}
}
delete function (not working)
function borrar(){
var cf = document.getElementsByName('atenuantes[]');
var cs = document.getElementsByName('agravantes[]');
for (i=0; i<cf.length; i++){
if(cf[i].checked = true){
cf[i].checked = false;
}
}
for (i=0; i<cs.length; i++){
if(cs[i].checked = true){
cs[i].checked = false;
}
}
}
and try to checkboxes manually and nothing happens
Also try to create a test file.js with function prueba(){alert("hola");}
and it will not run
here the form:
<?php
session_start();
// CONECTANDO AL SISTEMA SEGUN TIPO DE USUARIO//
if (isset($_SESSION['conectado'] ) && $_SESSION['conectado'] == true && $_SESSION['nivel']==1) {
require_once '__conexion.php';
include 'encabezado.php';
include 'funciones/JSON.php';
include 'funciones_php_generarSelects.php';
// ------------------------ //
} else {
// MENSAJE DE ACCESO NEGADO //
echo ('<script>alert("No tiene permisos suficientes para acceder a esta parte del sistema");</script>');
echo ("<script>window.location = 'index.php';</script>");
exit;
// ------------------------ //
}
// ------------------------ //
$now = time();
if($now > $_SESSION['expira']) {
//DESTRUYO LA SESION, ANTES DE SACARLO DEL SISTEMA//
session_destroy();
// MENSAJE DE SESIÓN EXPIRADA //
echo ('<script>alert("Su sesión ha expirado");</script>');
echo ("<script>window.location = 'index.php';</script>");
exit;
}
// ------------------------ //
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Sistema Automatizado de Orden de Medida Disciplinaria</title>
<!-- Librerias -->
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<!-- ///////// -->
<!-- Funciones -->
<script src="funciones/circunstancias_borrar.js"></script>
<script src="funciones/circunstancias_cambio.js"></script>
<script src="funciones/circunstancias_limite.js"></script>
<script src="funciones/circunstancias_refrescado.js"></script>
<script src="funciones/circunstancias_verificar.js"></script>
<script src="funciones/validar_longitud.js"></script>
<!-- FALTA VALIDAR LA OMD -->
<!-- ///////// -->
<!-- Hojas de Estilo -->
<link rel='stylesheet' href='recursos/css/estilo.css'>
<!-- /////////////// -->
</head>
<body onload="refrescado()">
<form id="omd" name="omd" method="POST" action="funciones/generarOMD.php" enctype="multipart/form-data">
<table width="593" border="3" align="center">
<tr>
<div>
Ingrese el número de cedula del sancionado:
<input type="text" id="cedula1" name="cedula1" oncopy="return false" onpaste="return false">
<input type="text" name="resultado1" id="resultado1" readonly>
</div>
<div>
Ingrese el número de cedula del sancionador:
<input type="text" id="cedula2" name="cedula2" oncopy="return false" onpaste="return false">
<input type="text" name="resultado2" id="resultado2" readonly>
<div>
Ingrese el número de cedula del superior:
<input type="text" id="cedula3" name="cedula3" oncopy="return false" onpaste="return false">
<input type="text" name="resultado3" id="resultado3" readonly>
<div>
Seleccione el artículo inflingido:
<select name="articulo" id="articulo">
<option value="0">Seleccione un articulo:</option>
<?php
listaArticulos();
?>
</select>
<div>
Seleccione el apartado:
<select id="apartado" name="apartado">
<option value="0">Seleccione primero un artículo</option>
</select>
<div>
Decripción de la falta:
<input type="text" id="desc_falta" name="desc_falta" readonly>
</div>
<div>
Seleccione el tipo de circunstancia influyente:
<input type="radio" name="tipo_circunstancia" id="ninguno" onclick="toggle(this); borrar()" value ="0" checked > Ninguno
<input type="radio" name="tipo_circunstancia" id="tipo_atenuante" onclick="toggle(this); borrar()" value="1"> Atenuantes
<input type="radio" name="tipo_circunstancia" id="tipo_circunstancia" onclick="toggle(this); borrar()" value="2"> Agravantes <br/>
</div>
<div id="uno">
Circunstancias Atenuantes:
<?php
listaAtenuantes();
?>
</div>
<div id="dos">
Circunstancias Agravantes:
<?php
listaAgravantes();
?>
</div>
<div>
Seleccione el estado:
<select>
<option value="0">Seleccione un estado</option>
<?php
listaEstados();
?>
</select>
</div>
<div>
Seleccione los documentos anexos:
<?php
echo "Documentos Anexos: ";
listaDocumentos();
?>
</div>
<div>
<p><STRONG>NOTA:</STRONG>
Cabe destacar que debe poseer <br>todos los documentos de<br> manera fisica
de lo contrario<br>, su orden de medida <br>disciplinaria sera remitida con un
oficio de devolución</p>
</div>
<div>
Ingrese la fecha del último ascenso
<input type="text" name="fecha_ascenso" readonly id="datepicker1">
</div>
<div>
Ingrese el cargo actual del sancionado:
<input type="text" name="cargo" id="cargo">
</div>
<div>
Seleccione el tipo de medida disciplinaria:
<select name="medida">
<option value="0">Seleccione una medida</option>
<?php
listaMedidas();
?>
</select>
</div>
<div>
Ingrese el número de días de la OMD:
<input type="text" name="dias" id="dias">
<p><STRONG>NOTA:</STRONG>
Las fechas de la OMD se calcularan automaticamente, despues de ingresar el número de días.
</div>
<div>
Fecha de inicio de la OMD:
<input type="text" name="fecha_inicio" readonly value="<?php echo $fecha_inicio=date('d-m-Y');?>">
</div>
<div>
fecha de termino de la OMD:
<input type="text" name="fecha_fin" readonly id="datepicker3" >
</div>
<div>
Aclaratoria de la falta:
<textarea cols="40" rows="5" name="aclaratoria" onKeyDown="valida_longitud()" onKeyUp="valida_longitud()" onBlur="aMays(event, this)"></textarea>
Carácteres ingresados / disponibles:
<input type="text" name="caracteres" size=4><input type="text" name="caracteres2" size=4>
</div>
</tr>
</table> <!-- TABLA DEL ESTANDAR-->
<table class="fin" align="center">
<tr>
<td colspan="4">
<input type="submit" name="submit" value="enviar">
<center><img width="50" height="50" onclick="location.href='funciones/generarOMD.php';" src="recursos/iconos/guardar.png" alt="GUARDAR"/>Guardar
<img width="50" height="50" onclick="location.href='menu_unidades.php';" src="recursos/iconos/salir.png" alt="SALIR"/>Atras</center>
</td>
</table>
</body>
</html>
Here the checkboxes
function listaAtenuantes()
{
global $conexion;
global $conexion;
$stmt = $conexion->prepare("SELECT id_aparte,desc_circunstancia FROM circunstancias WHERE id_articulo=40");
$stmt->execute();
$stmt->store_result();
$numfilas = $stmt->num_rows;
// echo $numfilas;
$stmt->get_result(); //obtener los resultados
$stmt->bind_result($stmt1, $stmt2); //asignarlos a las variables, cada variable debe ser un campo que obtengo del query
while ($stmt->fetch())
{
echo "</br>" . "<input type='checkbox' onclick='validacionMaximo(this);' name='atenuantes[]' value='" . $stmt1 . "'>" . $stmt2;
}
}
function listaAgravantes()
{
global $conexion;
global $conexion;
$stmt = $conexion->prepare("SELECT id_aparte,desc_circunstancia FROM circunstancias WHERE id_articulo=41");
$stmt->execute();
$stmt->store_result();
$numfilas = $stmt->num_rows;
// echo $numfilas;
$stmt->get_result(); //obtener los resultados
$stmt->bind_result($stmt1, $stmt2); //asignarlos a las variables, cada variable debe ser un campo que obtengo del query
while ($stmt->fetch())
{
echo "</br>" . "<input type='checkbox' onclick='validacionMaximo(this);' name='agravantes[]' value='" . $stmt1 . "'>" . $stmt2;
}
}