Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/03/2012, 16:15
tesistas
 
Fecha de Ingreso: septiembre-2010
Mensajes: 74
Antigüedad: 13 años, 7 meses
Puntos: 1
php con javascript no se ejecuta dentro de div cargado con ajax

Hola a todos, tengo una pagina php la cual tiene una funcion que sirve para habilitar o desabilitar cajas de texto luego de hacer click en los checkbox correspondientes. Esta pagina quiero cargarla en un div de otra pagina, esto lo hago con ajax. El problema es que cuando llamo a la pagina php para mostrarla en el div, la funcion deja de andar.

Primera pagina la cual tiene el div

Código HTML:
<script lang="javascript">
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}




//_________________________________________________________________________
function buscar(){ //esta es la funcion que envia los datos de manea asincrona
	//div donde  mostrararemos  los datos de la consulta 
	divResultado = document.getElementById('resultado');

	//tomamos el valor enviado del formulario de envio
	clave=document.formulario.clave.value;

	//instanciamos el objetoAjax
	ajax=objetoAjax();
	//usamos el medoto POST
	//archivo que realizará la operacion
	ajax.open("POST", "buscar_cod_vender.php",true);
	//mostramos una imagen mientras cargamos el resultado de la consulta
	//divResultado.innerHTML= '<img src="images/ajax.gif">';
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//visualizamos el resultado correscpondiente
			divResultado.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valoress
	ajax.send("clave="+clave)
}
</script>
<html>
    
    <form action="" name="formulario" >
<input type="text" id="clave"  > <button type="button" onClick="buscar()">buscar</button>
    </form>

<div id="resultado">

  </div>
</html> 
Segunda pagina, esta se cargara dentro del div de la primera y es la que tiene la funcion

Código HTML:
<?php
include_once 'lib.php';
$cod =$_POST['clave'];


$conexion= mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $conexion);
$result = mysql_query("SELECT id_stock, codigo, descrip, pre_min, pre_may, disponibles  FROM stock where activo = '1'and codigo = $cod", $conexion);
?>
<form name="vender" method="post" action="vender_prod.php">
    <table border="2">
        <tr>
            <th>ID</th>
            <th>Codigo</th>
            <th>Descrip</th>
            <th>Prec.Min</th>
            <th>Prec.May</th>
            <th>Disponibles</th>
            <th></th>
<!--            <th style='border: none'></th>-->
            <th>Cantidad</th>
 
        </tr>
        <?php
        $i = 0;
        while ($row = mysql_fetch_array($result)) {
            ?>
            <tr>
                <td><?php echo $row['id_stock'] ?></td>
                <td><?php echo $row['codigo'] ?></td>
                <td style="width: 500px"><?php echo $row['descrip'] ?></td>
                <td align="right"><?php echo "$"; echo $row['pre_min'] ?></td>
                <td align="right"><?php echo "$"; echo $row['pre_may'] ?></td>
                <td align="center"><?php echo $row['disponibles'] ?></td>
                <td><input id="chk_<?php echo $i ?>" name="seleccion[]" type="checkbox" value="<?php echo$row['id_stock'] ?>" class="chk"/></td>
<!--                <td style="border: none"></td>-->
                <td><input id=txt_<?php echo $i ?>" name="cantidad[]" disabled="disabled" type="text" style="width: 60" class="txt"/></td>  
            </tr>
 
            <?php
            $i++;
        }
        ?>
    </table>
    <br />
    <input type="submit" name="submit" value="Enviar">
</form>
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
    
    $(document).ready(function(){ 
       
        $(".chk").change(function(){
            var comentario = $( '.txt', $( this ).parents ( 'tr' ) );
            if( $(this).is(':checked')){            
                comentario.removeAttr('disabled');
            } else {
                comentario.attr('disabled', true);
            }
        });
    });
    
</script> 
Ayudaaaaaaaaaaa!!!