Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

shumi

Consultar CPF ao digitar no campo

Recommended Posts

Adriano,

me da um help aqui!

 

Tipo eu comecei a fazer e como os dois Ajax são no mesmo form eu mudei os nomes das funções tipo uma ta ajax a outra eu coloquei ajaxx e o nome do arquivo tb...

Veja se assim ta certo!

 

Ajaxx.JS

function ajaxx() {};ajaxx.prototype.iniciar = function() {	try{		this.xmlhttp = new XMLHttpRequest();	}catch(ee){		try{			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");		}catch(e){			try{				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			}catch(E){				this.xmlhttp = false;			}		}	}	return true;}ajaxx.prototype.ocupado = function() {	estadoAtual = this.xmlhttp.readyState;	return (estadoAtual && (estadoAtual < 4));}ajaxx.prototype.processa = function() {	if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {		return true;	}}ajaxx.prototype.enviar = function(url, metodo, modo) {	if (!this.xmlhttp) {		this.iniciar();	}	if (!this.ocupado()) {		if(metodo == "GET") {			this.xmlhttp.open("GET", url, modo);			this.xmlhttp.send(null);		} else {					this.xmlhttp.open("POST", url, modo);			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");			this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");			this.xmlhttp.setRequestHeader("Pragma", "no-cache");			this.xmlhttp.send(url);		}			if (this.processa) {			return unescape(this.xmlhttp.responseText.replace(/\+/g," "));		}	}	return false;}function enviaa(url, metodo, modo){	var cpf = document.getElementById('cpf').value;	remoto  = new ajaxx();	xmlhttp = remoto.enviar(url + "?cpf=" + cpf, metodo, modo);	if(xmlhttp) {		alert("Nunca foi contratado pela NewStyle");		document.getElementById("Enviar").disabled = false;	} else {		document.getElementById("Enviar").disabled = false;  }}

calculaa.asp

<%cpfultimo = request("cpf")Sqlcpf = "Select * From ficha_de_pessoal where cpf='"&cpfultimo&"'"Set rscpf = Conexcao.Execute(sqlcpf)If cpfultimo = rscpf("cpf") Then	response.Write falseElseResponse.Write(rscpf("data_inicio"))End if%>

Ta ok?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Entendi!

 

Assim:

 

function ajax() {};ajax.prototype.iniciar = function() {	try{		this.xmlhttp = new XMLHttpRequest();	}catch(ee){		try{			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");		}catch(e){			try{				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			}catch(E){				this.xmlhttp = false;			}		}	}	return true;}ajax.prototype.ocupado = function() {	estadoAtual = this.xmlhttp.readyState;	return (estadoAtual && (estadoAtual < 4));}ajax.prototype.processa = function() {	if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {		return true;	}}ajax.prototype.enviar = function(url, metodo, modo) {	if (!this.xmlhttp) {		this.iniciar();	}	if (!this.ocupado()) {		if(metodo == "GET") {			this.xmlhttp.open("GET", url, modo);			this.xmlhttp.send(null);		} else {					this.xmlhttp.open("POST", url, modo);			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");			this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");			this.xmlhttp.setRequestHeader("Pragma", "no-cache");			this.xmlhttp.send(url);		}			if (this.processa) {			return unescape(this.xmlhttp.responseText.replace(/\+/g," "));		}	}	return false;}function envia(url, metodo, modo){	var nasc = document.getElementById('str_data').value;	remoto  = new ajax();	xmlhttp = remoto.enviar(url + "?nasc=" + nasc, metodo, modo);	if(xmlhttp) {		alert("Não pode ser contratado com idade inferior a 18 anos completos");		document.getElementById("Enviar").disabled = true;	} else {		document.getElementById("Enviar").disabled = false;  }function enviaa(url, metodo, modo){	var cpf = document.getElementById('cpf').value;	remoto  = new ajax();	xmlhttp = remoto.enviar(url + "?cpf=" + cpf, metodo, modo);	if(xmlhttp) {		alert("Nunca foi contratado pela NewStyle");		document.getElementById("Enviar").disabled = false;	} else {		document.getElementById("Enviar").disabled = false;  }}

É isso???

as } estão certas? no fim de cada função envia e enviaa?

 

Abs

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara tem como você dar uma olhada naquele site que te passei por MP?Ta dando erro eu só inseri aquele bloco!Valeu!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Adrino,

Cara to embaralhadasso aqui.

 

Tava tentando fazer desde aquela hora veja que fiz:

 

Ajax.js

function ajax() {};ajax.prototype.iniciar = function() {	try{		this.xmlhttp = new XMLHttpRequest();	}catch(ee){		try{			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");		}catch(e){			try{				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			}catch(E){				this.xmlhttp = false;			}		}	}	return true;}ajax.prototype.ocupado = function() {	estadoAtual = this.xmlhttp.readyState;	return (estadoAtual && (estadoAtual < 4));}ajax.prototype.processa = function() {	if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {		return true;	}}ajax.prototype.enviar = function(url, metodo, modo) {	if (!this.xmlhttp) {		this.iniciar();	}	if (!this.ocupado()) {		if(metodo == "GET") {			this.xmlhttp.open("GET", url, modo);			this.xmlhttp.send(null);		} else {					this.xmlhttp.open("POST", url, modo);			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");			this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");			this.xmlhttp.setRequestHeader("Pragma", "no-cache");			this.xmlhttp.send(url);		}			if (this.processa) {			return unescape(this.xmlhttp.responseText.replace(/\+/g," "));		}	}	return false;}function envia(url, metodo, modo){	var nasc = document.getElementById('str_data').value;	remoto  = new ajax();	xmlhttp = remoto.enviar(url + "?nasc=" + nasc, metodo, modo);	if(xmlhttp) {		alert("Não pode ser contratado com idade inferior a 18 anos completos");		document.getElementById("Enviar").disabled = true;	} else {		document.getElementById("Enviar").disabled = false;  }}function enviaa(url, metodo, modo){	var cpf = document.getElementById('cpf').value;	remoto  = new ajax();	xmlhttp = remoto.enviar(url + "?cpf=" + cpf, metodo, modo);	if(xmlhttp) {		alert("Nunca foi contratado pela NewStyle");		document.getElementById("Enviar").disabled = false;	} else {		document.getElementById("Enviar").disabled = false;  }}

calculaa.asp

<!--#include file="includes/conecao.asp"--><%cpfultimo = Request("cpf")Sqlcpf = "Select ficha_de_pessoal.codmovimeta,ficha_de_pessoal.cpf,substituicao.funcionario_que_tava,substituicao.data_fim From substituicao,ficha_de_pessoal Where ficha_de_pessoal.cpf='"&cpfultimo&"' and substituicao.funcionario_que_tava = ficha_de_pessoal.codmovimeta"Set rscpf = Conexcao.Execute(Sqlcpf)IF rscpf.EOF ThenResponse.Write("Não há registros de contatações anteriores")Else IF cpfultimo = rscpf("cpf") ThenResponse.write(rscpf("data_fim"))End IFEnd IFif rscpf.eof = True Then	response.Write false	End if%>

e tem meu form ta mais ou menos assim:

<form name="cad" id="cad" method="post" action="ficha_de_pessoal_valida1.asp" onSubmit="return envia('calculaa.asp','GET',false);">

Como eu devo chamar meu campo para aparecer a mensagem???

 

Abraços

Compartilhar este post


Link para o post
Compartilhar em outros sites

Grande Adriano!quando você tiver um tempinho pode me ajudar?Não to conseguindo fazer funfar.Acredito que seja pouca coisa, alguns detalhes, sei la!É que tenho o campo CPF no meu form ai tenho o campo ultima_contratacao e teria que aparecer nesse campo o status, mas nada aontece.eu não sei onde eu tenho que apontar que é para aparecer nesse campo.Depois me da um help aqui ok?!?Abraços

Compartilhar este post


Link para o post
Compartilhar em outros sites

Primeiro eu vou tentar fazer aparecer essa mensagem mesmo que você colocou depois vou tentar fazer aparecer a data...Tem como você entrar no site que eu vou te mandar por MP pra você dar uma olhada o pq não ta funfando???Abraços

Compartilhar este post


Link para o post
Compartilhar em outros sites

Foi mal a falta de atenção é que ainda não me acustumei com o AJAX...Cara dá uma olhada lá não ta retornando mesmo eu mudando isso..deve ter mais alguma coisa errada minha.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Funfouuuuuuuuuuuuuuuuuuuuuuuuuuuu!!!!!!!!!!!!!!!!!!!!!! http://forum.imasters.com.br/public/style_emoticons/default/clap.gif http://forum.imasters.com.br/public/style_emoticons/default/clap.gif http://forum.imasters.com.br/public/style_emoticons/default/clap.gif http://forum.imasters.com.br/public/style_emoticons/default/clap.gif http://forum.imasters.com.br/public/style_emoticons/default/clap.gif

 

Agora me ajuda a linkar no meu form de verdade???

Pq ai eu fiquei com 2 ajax.js

 

esse

//-----------------------------------------------------------------------------// Define some constants.//-----------------------------------------------------------------------------// Define a list of Microsoft XML HTTP ProgIDs.var XMLHTTPREQUEST_MS_PROGIDS = new Array(	"Msxml2.XMLHTTP.7.0",	"Msxml2.XMLHTTP.6.0",	"Msxml2.XMLHTTP.5.0",	"Msxml2.XMLHTTP.4.0",	"MSXML2.XMLHTTP.3.0",	"MSXML2.XMLHTTP",	"Microsoft.XMLHTTP");// Define ready state constants.var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;var XMLHTTPREQUEST_READY_STATE_LOADING	   = 1;var XMLHTTPREQUEST_READY_STATE_LOADED		= 2;var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;var XMLHTTPREQUEST_READY_STATE_COMPLETED	 = 4;//-----------------------------------------------------------------------------// Returns an XMLHttpRequest object.//-----------------------------------------------------------------------------function getXMLHttpRequest(){	var httpRequest = null;	// Create the appropriate HttpRequest object for the browser.	if (window.XMLHttpRequest != null)		httpRequest = new window.XMLHttpRequest();	else if (window.ActiveXObject != null)	{		// Must be IE, find the right ActiveXObject.		var success = false;		for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)		{			try			{				httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);				success = true;			}			catch (ex)			{}		}	}	// Display an error if we couldn't create one.	if (httpRequest == null)		alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");	// Return it.	return httpRequest;}//-----------------------------------------------------------------------------// This code uses an XMLHttpRequest object to look up the city and state of the// ZIP code entered by the user. That data is then used to populate the// corresponding form fields.//-----------------------------------------------------------------------------var cityStateLookup = getXMLHttpRequest();function ProcurarCompativel(event){	// Clear the status text.	//setStatusText("");	// Check for a zip code.	var Codigo = document.getElementById("cpf").value;	// Perform an asynchronous request to get the matching city and state.	var url = "pesquisabanco.asp?Codigo=" + Codigo;	cityStateLookup.onreadystatechange = cityStateReadyStateChange;	cityStateLookup.open("GET", url, true);	cityStateLookup.send(null);}function cityStateReadyStateChange(){	//var statusText;	// Check the ready state.	switch (cityStateLookup.readyState)	{		case XMLHTTPREQUEST_READY_STATE_UNINITIALIZED:			//statusText = "";			break;		case XMLHTTPREQUEST_READY_STATE_LOADING:			//statusText = "Initialzing ZIP Code lookup...";			break;		case XMLHTTPREQUEST_READY_STATE_LOADED:			//statusText = "Sending data...";			break;		case XMLHTTPREQUEST_READY_STATE_INTERACTIVE:			//statusText = "Downloading data...";			break;		case XMLHTTPREQUEST_READY_STATE_COMPLETED:			// Assume no match was found.			//statusText = "ZIP Code not found."			// Fill in the city and state fields, if available.			try			{				var data = cityStateLookup.responseText.split(",");				if (data.length == 1)				{					document.getElementById("ultimo_registro").value  = data[0];					//statusText = "ZIP Code found."				}			}			catch (ex)			{}			break;		default:			//statusText = "Unknown error.";			break;	}	// Update the status message.	}function setStatusText(text){   	var el = document.getElementById("statusText");	if (el.firstChild == null)		el.appendChild(document.createTextNode(""));	el.firstChild.nodeValue = text;}

e esse

function ajax() {};ajax.prototype.iniciar = function() {	try{		this.xmlhttp = new XMLHttpRequest();	}catch(ee){		try{			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");		}catch(e){			try{				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			}catch(E){				this.xmlhttp = false;			}		}	}	return true;}ajax.prototype.ocupado = function() {	estadoAtual = this.xmlhttp.readyState;	return (estadoAtual && (estadoAtual < 4));}ajax.prototype.processa = function() {	if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {		return true;	}}ajax.prototype.enviar = function(url, metodo, modo) {	if (!this.xmlhttp) {		this.iniciar();	}	if (!this.ocupado()) {		if(metodo == "GET") {			this.xmlhttp.open("GET", url, modo);			this.xmlhttp.send(null);		} else {					this.xmlhttp.open("POST", url, modo);			this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");			this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");			this.xmlhttp.setRequestHeader("Pragma", "no-cache");			this.xmlhttp.send(url);		}			if (this.processa) {			return unescape(this.xmlhttp.responseText.replace(/\+/g," "));		}	}	return false;}function envia(url, metodo, modo){	var nasc = document.getElementById('str_data').value;	remoto  = new ajax();	xmlhttp = remoto.enviar(url + "?nasc=" + nasc, metodo, modo);	if(xmlhttp) {		alert("Não pode ser contratado com idade inferior a 18 anos completos");		document.getElementById("Enviar").disabled = true;	} else {		document.getElementById("Enviar").disabled = false;  }}function enviaa(url, metodo, modo){	 var cpf = document.getElementById('cpf').value;	 remoto  = new ajax();	 xmlhttp = remoto.enviar(url + "?cpf=" + cpf, metodo, modo);	 if(xmlhttp) {		 alert("Nunca foi contratado pela NewStyle");		 document.getElementById("ultima_contratacao").value = "NUNCA foi contratado!";	 } else {		 document.getElementById("ultima_contratacao").value = "JÁ foi contratado!";}}

Compartilhar este post


Link para o post
Compartilhar em outros sites

No meu IE ta funfando e agora testei no FF não ta funfando!

Eu mudei para onBlur, mas no FF continua não rolando!

 

Acessando o end http://www.newstyle1.com/sis/formcpf.asp

e o Parlamentar você coloca 111.111.111-11

Ai no partido vai aparecer 12/6/1990

Compartilhar este post


Link para o post
Compartilhar em outros sites

Adriano o Ajax não faz 2 consutas sem eu apertar pra atualizar???

Tipo se eu consulto um cpf e depois quero outro ele não volta atualiza a data de contratação a não ser se eu atualizo a pagina.

É assim mesmo???

 

veja:

http://www.newstyle1.com/sis/formcpf.asp

 

testa o CPF 111.111.111-11 e depois teste o 555.555.555.555-55

 

Abraços

Compartilhar este post


Link para o post
Compartilhar em outros sites

Aqui atualizou!!! Apareceu "Não houve..."

No meu PC não, mas conferi no MAC e em outro PC e funfou certinho.

O meu PC que deve estar armazenando em Cache.

Meu PC se eu limpo tudo ele continua salvando ate as paginas que eu acesso! rs

beleza ta funfando!

 

Velau

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.