el codigo resumido:
Código PHP:
   form name='add' form action="admin.php" method="post">
<input type="hidden" name="accion" value="Insertar" />
<table width="36%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30" colspan="2" bgcolor="#AEB8DD"><div align="center">Nuevo Articulo</div></td>
    </tr>
  <tr>
    <td width="24%" bgcolor="#CFD0FC"><div align="right">Codigo </div></td>
    <td width="76%" height="28" bgcolor="#CFD0FC"><label>
      <input name="codigo" type="text" id="codigo" size="20"  maxlength="20"/>
      <script languaje="javascript">
        document.getElementById('codigo').onblur = getDataNOMBRE;
        document.getElementById('codigo').focus();
          </script>
    </label></td>
  </tr> 
   Código PHP:
   <script type="text/javascript" src="ajax.js"></script>
    <script languaje="javascript">
    var ajax = new sack();
    var currentClientID=false;
    
    String.prototype.trim = function() {
    return this.replace(/^\s*|\s*$/g,"");
    }
 
function getDataNOMBRE()
    {
        var nombre_i = document.getElementById('codigo').value.replace(/(^[a-zA-Z0-9.@]$)/g,'');
        
            nombre_i = nombre_i.trim();
            if(nombre_i!=currentClientID)
                                                
            currentClientID = nombre_i
            ajax.requestFile = 'datos.php?getnombre_i='+nombre_i;
            ajax.onCompletion = showClientData;    
            ajax.runAJAX();                
    }
    
    function showClientData()
    {
        var formObj = document.forms['add'];    
        eval(ajax.response);
    }
</script> 
   Código PHP:
   <?php
include ("conexion.php");
$link=conectar();        
 
if(isset($_GET['getnombre_i'])){ 
$VALOR=$_GET['getnombre_i'];
        $consulta = "select * from articulo where codigo ='$VALOR'"; 
        $resultado = mysql_query($link,$consulta);
        if($datos = mysql_fetch_array($resultado)){
  ?>
  alert("El codigo ya existe");
  document.add.codigo.select();
  document.add.codigo.focus();
  <?php
  }         
}
mysql_close($link); 
?>    
 
Este tema le ha gustado a 1 personas