
02/10/2009, 15:09
|
 | | | Fecha de Ingreso: marzo-2009
Mensajes: 101
Antigüedad: 15 años, 11 meses Puntos: 0 | |
Respuesta: variable indefinida con checkbox codigo javascritp
Código:
function usuario_eliminar_mail(nombreF, cadena)
{
var quitar = "&;|;#";//los valores a remover del formulario
var Formulario = document.getElementById(nombreF);//recibe el id del formulario
var longitud = Formulario.elements.length;
var campos = "";
var separador;
//alert (Formulario);
separador = "";
sw = 0;
cont = 0;
inicio = 1;
numero_de_campos = 4;//sirve para poner el separador maestro, si quiero poner dos campos coloco 3 en numero de campos
j = 0;
if(document.getElementById("mens1") != null)
{
inicio = inicio + 1;
}
if(document.getElementById("mens2") != null)
{
inicio = inicio + 1;
}
for (i = inicio; i < longitud; i++)
{
if(cont >= 0)
{
if(sw == 0)
{
separador = "";
sw = 1;
}
else
{
separador = "|";
}
cont = cont + 1;
if(cont == numero_de_campos)
{
separador = "#";
cont = 1;
}
}
if(Formulario.elements[i].type == "checkbox")
{
if(Formulario.elements[i].checked == true)
val = 1;
if(Formulario.elements[i].checked == false)
val = 0;
valorF = val;
}
if(Formulario.elements[i].type != "checkbox")
{
valorF = Formulario.elements[i].value;
}
valorF = reemplazar_caracter(valorF, quitar);
campos += separador+Formulario.elements[i].id+'='+(valorF);
}//
valores = "campos="+campos;
alert(campos);
ajax = nuevoAjax();
ajax.open("POST", "./usuario_eliminar_mail.php", true);
ajax.onreadystatechange=function()
{
if(ajax.readyState == 1)
{
document.getElementById("tdmensajes1").innerHTML = "<img src='./../images/loading.gif' border='0'>";
document.getElementById("tdmensajes2").innerHTML = " Actualizando datos...";
}
if(ajax.readyState == 4)
{
document.getElementById("tdmensajes1").innerHTML = "";
document.getElementById("tdmensajes2").innerHTML = ajax.responseText;
if(document.getElementById("mens") != null)
{
var mens = document.getElementById("mens").value;
//alert(mens);
if(mens == 1)
{
alert("YOUR REQUEST WAS SUCCESSFULLY PROCESSED")
location.href = "./../paginas/usuario_mail_ver.php";
}
if(mens == 2)
{
alert("ERROR try again")
}
}
}
}
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
ajax.send(valores);//*/
}
[/CODE]
codigo php elimina
Código:
<?php
include('../funciones/error.php');
include('../funciones/funciones.php');
include('../funciones/class_conexion.php');
include('../funciones/paginator.php');
include('../funciones/paginator_html.php');
$BD = new class_conexion();
valida_session();
global $mens, $id_mail_COM, $id_usuario_COM, $check_mail_COM,$campos,$registro ;
/*foreach ($_POST as $c => $v)
echo $c." = ".$v."<br>";*/
$campos = $_POST['campos'];
$fhregistro = getDateTime('tstamp');
$campos = explode("#", $campos);
$longitud = count($campos);
//echo "Longitud ".$longitud."<br>";
$mensaje = "RESULTADO DE LA OPERACION:\n\n";
$cont = 0;//PARA CONTAR CUANTAS NO FUERON CHEQUEADAS
foreach($campos as $registro)
{
$fila = explode("|", $registro);
$id_mail_i = explode("=", $fila[0]);
$id_usuario_i = explode("=", $fila[1]);
$check_mail_i = explode("=", $fila[2]);
$id_mail = $id_mail_i[1];
$id_usuario = $id_usuario_i[1];
$check_mail = trim($check_mail_i[1]);
//echo "id_mail_COM = ".$id_mail_COM."<br> id_usuario_COM = ".$id_usuario_COM."<br> check_mail_COM =".$check_mail_COM."<br>";
if( ($id_mail!= "") and ($id_usuario != "") and ($check_mail != "") )
{
//echo "IDSUCURSAL ".$idsucursalVEC." | CHK ".$check_sucursal." | DESC ".$descripcion."<br>";
$prim = "SELECT id_usuario
FROM usuarios_mensajes_mail
WHERE id_mail = ".$id_mail." AND id_usuario = ".$id_usuario."";
$rprim = $BD->ejecutar_sql($prim);
$fila = $BD->fetch_array($rprim);
//echo "sql = ".$prim."<br>";
$id_usuario = $fila["id_usuario"];
//echo "mail = ".$check_mail_COM."<br> id = ".$id_usuario_COM."<br> chekeo = ".$check_mail_COM."<BR>";
if($check_mail == 1)
{
//echo "id_mail".$id_mail_COM;
/*if($check_mail_COM == 0)
{
$check_mail_COM == 1;
}*/
$sql = "DELETE
FROM usuarios_mensajes_mail
WHERE id_mail = ".$id_mail." AND id_usuario = ".$id_usuario."";
$result = $BD->ejecutar_sql($sql);
//echo "sql = ".$sql."<br>";
if($result)
{
//echo "estoy aca";
$mens = 1;
}
else
{
//echo "estoy aca2";
$mens = 2;
}//*/
}
/*if( (trim($sql) == "") and ($cont == $longitud) )
{
$mens = 3;
$mensaje.= "=> NO HA SELECCIONADO NINGUNA SUCURSAL.";
}*/
}//fin si hay sucursal*/
}
/*else
{
$mens = 4;
}*/
if($mens != "")
{
echo "<input type='hidden' id='mens' value='".$mens."'>";
}
?>
la variable viajan asi
campos = id_mailadmin0=2|id_usuarioadmin0=1|check_mailadmin 0=1#=undefined|id_mailadmin1=1|id_usuarioadmin1=1# check_mailadmin1=1|=undefined
que puede ser ayuda |