Ver Mensaje Individual
  #11 (permalink)  
Antiguo 13/02/2008, 14:48
Avatar de Shiryu_Libra
Shiryu_Libra
Colaborador
 
Fecha de Ingreso: febrero-2007
Ubicación: Cantando "Screenager" en "Kirafa Kaput"
Mensajes: 3.614
Antigüedad: 18 años, 2 meses
Puntos: 88
Re: Formulario con Asp, Generando Codigo Correlativo Segun datos!

veamos.....

deberas agregar el siguiente codigo entre las etiquetas HEAD donde tienes tu formulario
Código PHP:
<script language="javascript" type="text/javascript">
/* NO BORRAR ESTA SECCION*/
var enProceso false// lo usamos para ver si hay un proceso activo
var http getHTTPObject(); // Creamos el objeto XMLHttpRequest

function getHTTPObject() {
    var 
xmlhttp;
    
/*@cc_on
    @if (@_jscript_version >= 5)
       try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
           } catch (e) {
          try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; } }
    @else
        xmlhttp = false;
    @end @*/
    
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
xmlhttp = new XMLHttpRequest();
       } catch (
e) { xmlhttp false; }}
    return 
xmlhttp;}

/* ESTA FUNCION MANEJARA LA RESPUESTA */
function handleHttpResponse() {
if (
http.readyState == 4) {
    if (
http.status == 200) {
        if (
http.responseText.indexOf('invalid') == -1){
            
results http.responseText.split(",");
            if(
results[0]=="error"){alert(results[1]);}
            else{
document.getElementById(results[0]).innerHTML results[1];}
            
enProceso false;}
        }
    else
            {
            
results http.responseText.split(",");
            
document.getElementById(results[0]).innerHTML results[1];
            
enProceso false;
            }
    }
}

/* ESTA FUNCION ENVIARA LA RESPUESTA*/
function Codigo(Par1,Par2,Donde) {
if(
Par1==""){alert("debe elejir su estado");}
else{if(
Par2==""){alert("Debe seleccionar Persona Juridica/Normal");}
    else{if (!
enProceso && http) {
            
UID document.getElementById(UserID).value;
            
UST document.getElementById(UserStatus).value;
            var 
url "Pagina2.asp?UI="Donde "_" Par2 Par1 "&UID="Math.random();
            
http.open("GET"urltrue);
            
http.onreadystatechange handleHttpResponse;
            
enProceso true;
            
http.send(null);}}}}
</script> 
y hay que modificar el SELECT, donde tienes tu estado de la siguiente forma
Cita:
<select name="ub_cte" id="ub_cte" onchange="Codigo(this.id,'tip_cte','rif_cte2')">
debera crear una segunda pagina en la cual contendra el siguiente codigo, para regresarte tu correlativo.....

NOTA:... deberas poner nombre y enlazarlo perfectamente en el codigo de AJAX
Código PHP:
<%
if 
isnull(request.QueryString("UI")) then 
    respuesta 
"error,Error de conexion pagina no disponible"
else
    
'SEPARAMOS EL IDENTIFICADOR DE MENSAJES, DE LOS VALORES A TRATAR
    a = split(request.QueryString("UI"),"_")
    '
VOLVEMOS A SEPARAR LOS DATOS PARA LAS EJECUCIONES PERTINENTES
    
if a(1)="-" then 
        respuesta 
"Error en datos"
    
else
        
codigo=a(1)
        
query="select top 1 id_codigo from TUTABLA where id_codigo like '%" codigo "' order by id_codigo desc"
        
set RS=conexion.execute(query)
        if 
Err=0 then
            
if RS.eof=false then
                ultimo
=rs.fields.item("id_codigo").value
            
else
                
ultimo="0000"
            
end if
        else
            
respuesta="Error de consulta"
        
end if
        
rs.close
        conexion
.close
        set conexion
=nothing
        
'ya una ves que tengamos respuesta, hay que manipular el 
        '
resultado para incrementar el correlativo
        modificacion
=cint(left(ultimo,4))
        
select case len(modificacion)
            case 
1    modificacion="000" & (modificacion+1)
            case 
2    modificacion="00" & (modificacion+1)
            case 
3    modificacion="0" & (modificacion+1)
            case 
4    modificacion="" (modificacion+1)
        
end select
        respuesta 
modificacion codigo
    end 
if
end if
respuesta=a(0) & "," respuesta
response
.Write respuesta
response
.End()
%> 
haz una prueba con tu nuevo codigo, postea cualquier error para adaptacion


Nota: tambien deberas cambiar en la sentencia de consulta "QUERY", los nombres de los campos y la tabla, para que no te marque error, fijarse antes de realizar la consulta

sera posible que funcione...... ????
__________________
"Eres parte del problema, parte de la solucion o parte del paisaje"
Un Saludo desde Desierto de Altar, Sonora, MX.
Shiryu_libra