Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/03/2011, 15:16
theblackshyp
 
Fecha de Ingreso: febrero-2011
Mensajes: 25
Antigüedad: 13 años, 2 meses
Puntos: 0
Exclamación Problema javascript Ajax externo en html

Hola gente he buscado y leido sobre este problema q tengo, pero no he encontrado nada, quizas busque mal. La cosa es q no puedo lograr que se ejecute mi script.
A continuacion voy a poner mi codigo:
Código Codigo php:
Ver original
  1. <head>
  2. <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  3. <title>registro</title>
  4. <script language="javascript" type="text/javascript" src="validaciones.js"></script>
  5. </head>
  6.  
  7. <body>
  8. <p>
  9. <label id="usuario" style="display:block;width:145px;float:left">Usuario:</label>
  10. <input id="inputcuenta" name="cuenta" onblur="javascript:validar_cuenta(this);" size="30" type="text" maxlength="25" title="Tu usuario unico, 6 a 25 caracteres" />
  11. <label id="estadocuenta"></label><br/>
  12. <label id="errorcuenta" style="width: 211px"></label>
  13. </p>
  14. </body>

esa es una parte de mi formulario, lo unico q llamo es a la funcion validar_cuenta. Ahora les muestro el js

Código validacionreg.js:
Ver original
  1. function validar_cuenta(variable){
  2. var varsa=variable.value;
  3. var valcuenta = /^[-_\w]+$/i;
  4.  
  5. if(variable.value.match(valcuenta)){
  6.     if(variable.value.length >= 6){
  7.         ajax=CrearAjax();
  8.         if (ajax==null){
  9.         alert ("Tu navegador no soporta AJAX! No podras usar esta aplicación.");
  10.         return;}
  11.     var url="http://localhost/consulta_usuario.php";
  12.     url=url+"?cuenta="+varsa;
  13.     ajax.open("GET", url, true);
  14.     ajax.onreadystatechange=function(){
  15.         if(ajax.readyState==1){
  16.             document.getElementById("estadocuenta").appendChild(document.createTextNode(" Cargando..."));
  17.         }else{
  18.                 if (ajax.readyState==4){
  19.                     if(ajax.responseText == "fail"){
  20.                    
  21.                     document.getElementById('inputcuenta').style.color="red";
  22.                     document.getElementById('inputcuenta').style.borderColor="red";
  23.  
  24.                     document.getElementById('errorcuenta').style.color="red";
  25.                     document.getElementById('errorcuenta').style.fontWeight="bold";
  26.                     document.getElementById('errorcuenta').innerHTML="Usuario ya registrado";
  27.  
  28.                     document.getElementById('estadocuenta').style.fontWeight="bold";
  29.                     document.getElementById('estadocuenta').style.color="red";
  30.                     document.getElementById('estadocuenta').innerHTML="FAIL";
  31.                    
  32.                     }else{
  33.                     document.getElementById('inputcuenta').style.color="green";
  34.                     document.getElementById('inputcuenta').style.borderColor="green";
  35.  
  36.                     document.getElementById('estadocuenta').style.color="green";
  37.                     document.getElementById('estadocuenta').style.fontWeight="bold";
  38.                     document.getElementById('estadocuenta').innerHTML="OK";
  39.  
  40.                     document.getElementById('errorcuenta').style.color="green";
  41.                     document.getElementById('errorcuenta').style.fontWeight="bold";
  42.                     document.getElementById('errorcuenta').innerHTML="Usuario Valido";}
  43.                 }
  44.              }
  45.     }
  46.     ajax.send(null);
  47. }else{
  48. document.getElementById('inputcuenta').style.color="red";
  49. document.getElementById('inputcuenta').style.borderColor="red";
  50.  
  51. document.getElementById('errorcuenta').style.color="red";
  52. document.getElementById('errorcuenta').style.fontWeight="bold";
  53. document.getElementById('errorcuenta').innerHTML="Minimo 6 caracteres";
  54.  
  55. document.getElementById('estadocuenta').style.fontWeight="bold";
  56. document.getElementById('estadocuenta').style.color="red";
  57. document.getElementById('estadocuenta').innerHTML="FAIL";
  58. }
  59. }else{
  60. document.getElementById('inputcuenta').style.color="red";
  61. document.getElementById('inputcuenta').style.borderColor="red";
  62.  
  63. document.getElementById('errorcuenta').style.color="red";
  64. document.getElementById('errorcuenta').style.fontWeight="bold";
  65. document.getElementById('errorcuenta').innerHTML="Solo letras, numeros y guiones";
  66.  
  67. document.getElementById('estadocuenta').style.fontWeight="bold";
  68. document.getElementById('estadocuenta').style.color="red";
  69. document.getElementById('estadocuenta').innerHTML="FAIL";
  70. }
  71.  
  72. }
esa es una parte del archivo js, las funciones que invoco(como crearAjax, tambien la variable ajax la defini de manera global) si se encuentran en el archivo js pero por falta de espacio no las pongo aqui.

Gracias.