Foros del Web » Programando para Internet » Javascript »

Problema para llamar funcion javascript desde html

Estas en el tema de Problema para llamar funcion javascript desde html en el foro de Javascript en Foros del Web. Tengo el siguiente formulario que hace el llamado a la funcion validar, soy nuevo en ajax, me marca error diciendo se requiere un objeto: Código ...
  #1 (permalink)  
Antiguo 23/01/2009, 09:13
Avatar de mark_ant0n  
Fecha de Ingreso: enero-2009
Ubicación: Comitan, Chiapas mx
Mensajes: 388
Antigüedad: 15 años, 3 meses
Puntos: 6
Problema para llamar funcion javascript desde html

Tengo el siguiente formulario que hace el llamado a la funcion validar, soy nuevo en ajax, me marca error diciendo se requiere un objeto:
Código PHP:
function formulario($idioma_,$error){
   include(
$idioma_);
   echo
"<script src='java1.js'></script>";
   
//print"<form method='post' action='?mod=mod_usua'>"
   
print"<form >"
   
."<table width='241' border='0' align='center'>"
   
."<tr><td colspan='2'>".$BIEVENIDO_USU."</td>"
   
."</tr><tr>"
   
."<td width='72'>".$USUA."</td>"
   
."<td width='159'><input type='text' name='txtusu' /></td>"
   
."</tr><tr>"
   
."<td>".$CONT."</td>"
   
."<td><input type='password' name='txtcon' /></td>"
   
."</tr><tr>"         //en esta parte llamo la funcion validar   
   
."<td><input type='button'  onclick='validar()' value=".$BOTON_ENVIAR."></td>"
   
."<td><input type='reset' name='Submit2' value=".$BOTON_LIMPIAR."></td>"
   
."</tr><tr>"
   
."<td colspan='2'>".$error."</td>"
   
."</tr>"
   
."</table>"
   
."</form>";

mi codigo en javascript es el siguiente cual esmi error¿?

Código HTML:
function nuevoAjax(){
   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 validar(){
   var  contenedor;
   contenedor = document.getElementById('contenedor');
   t1 = document.getElementById('txtusu').value;
   t2 = document.getElementById('txtcon').value;
   ajax=nuevoAjax();
   ajax.open("GET", "?mod=mod_usua&&t1="+t1+"&&t2="+t2+"opcion=si",true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
      contenedor.innerHTML = ajax.responseText
       }
   }
   ajax.send(null)
}
gracias por su ayuda
  #2 (permalink)  
Antiguo 23/01/2009, 09:19
Avatar de mdague  
Fecha de Ingreso: septiembre-2008
Ubicación: Montevideo
Mensajes: 14
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Problema para llamar funcion javascript desde html

No pude ver tu codigo, xq estoy corto de tiempo ahora..
Pero lo que te queria decir es que si sos nuevo en AJAX lo mejor que puedes hacer es usar prototype. Es muuuuuy facil de aprender e implementar.
Te paso la direccion para que puedas bajarlo y ver la documentacion:
http://www.prototypejs.org/

Documentacion:
http://www.prototypejs.org/learn/introduction-to-ajax

Saludos
  #3 (permalink)  
Antiguo 23/01/2009, 09:23
Avatar de mark_ant0n  
Fecha de Ingreso: enero-2009
Ubicación: Comitan, Chiapas mx
Mensajes: 388
Antigüedad: 15 años, 3 meses
Puntos: 6
Respuesta: Problema para llamar funcion javascript desde html

Ok gracias lo que pasa es que es un proyecto de la escuela y pues mis revisores no quieren que maneje codigo ya hecho, pero de todos modos gracias mdague
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:06.