Ir para conteúdo
Fórum Script Brasil
  • 0

chamar varias funções diferentes para um mesmo campo do formulario


akira2005

Pergunta

2 respostass a esta questão

Posts Recomendados

  • 0

Depende muito do que quer fazer....

Eu pensaria em princípio em fazer uma função que chama outra.

Mas vai depender de como está seu código, talvez do jeito que está não seja possível isso, deve fazer algumas alterações.

Link para o comentário
Compartilhar em outros sites

  • 0

Esse código abaixo esta funcionando, possui duas funções em javascript uma validação simples e outra são mascaras dos campos do formulário para cpf, rg, cnpj.. etc, que estão dentro do cabeçalho(head), mas não quero que fique no head, quero que fique em arquivo externo tipo funcoes.js, para poder chama-las e funcionar, blza. Como faria pra chamar através do formulário essas duas funções que esta em uma arquivo externo(funcoes.js) para que funcione como se estivesse no cabeçalho, entendeu.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>cadastrar Empresa</title>
<style type="text/css">

body{
padding:0;
margin:0 10px;
color:#333;
background:#fff;
font:12px arial,verdana,sans-serif;
text-align:center;
}

#cadastro {
float: left;
margin: 0 10px;

}

form{margin:0;padding:0;}

fieldset{margin:1em 0; border:none; border:1px solid #ccc; width:450px;}

legend{margin:1em 0; padding:0 .5em; color:#036; background:transparent; font-size:1.3em; font-weight:bold;}

label{
float: left;
width: 125px;
font-weight: bold;
font: 12px verdana, arial, helvetica, sans-serif;
color: #111;
text-align:left;
margin-left: 10px;

}

input, select {

float:left;
width: 240px;
margin-bottom: 5px;
font: 12px verdana, arial, helvetica, sans-serif;
color: #0F578C;
border-left: 2px solid #80B0DA;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
border-right: 1px solid #ccc;
margin-left: 25px;

}

#botao{
font: 12px verdana, arial, helvetica, sans-serif;
margin-left: 315px;
margin-top: 5px;
width: 80px;
background-color: #FFFFFF;
color: #000;
border: 1px solid #80B0DA;
}

.ddd {
width: 20px;
}

#telefone, #fax {
width: 190px;

}

#contato {
width: 240px;
}

br{ clear: left; }
</style>
&lt;script type="text/javascript">

// validar campos

function confere (cadastro)
{

if(cadastro.cnpj.value=="") {
alert("Digite um CNPJ válido!");
return false;
}
if(cadastro.razsocial.value=="") {
alert("Digite A Razão Social!");
return false;
}
if(cadastro.inscest.value=="") {
alert("Digite a Inscrição Estadual/Municipal!");
return false;
}
if(cadastro.ramoativ.value=="") {
alert("Digite o seu ramo de Atividade!");
return false;
}
if(cadastro.endereco.value=="") {
alert("Digite o Endereço!");
return false;
}
if(cadastro.cep.value=="") {
alert("Digite um CEP Válido!");
return false;
}
if(cadastro.bairro.value=="") {
alert("Digite o Bairro!");
return false;
}
if(cadastro.cidade.value=="") {
alert("Digite a Cidade!");
return false;
}
if(cadastro.estado.value=="") {
alert("Digite o Estado!");
return false;
}
if(cadastro.numfuncionario.value=="") {
alert("Digite o Número de Funcionários!");
return false;
}
if(cadastro.contato.value=="") {
alert("Digite o Responsável pelo Contato!");
return false;
}
if(cadastro.ddd.value=="") {
alert("Digite o DDD!");
return false;
}
if(cadastro.telefone.value=="") {
alert("Digite o Telefone!");
return false;
}
if(cadastro.dddfax.value=="") {
alert("Digite o DDD do Fax!");
return false;
}
if(cadastro.fax.value=="") {
alert("Digite o número do Fax!");
return false;
}
if(cadastro.email.value=="") {
alert("Digite o E-mail!");
return false;
}
if(cadastro.tipodeproposta.value=="") {
alert("Preencha a Proposta!");
return false;
}
if(cadastro.senha.value=="") {
alert("Preencha um Senha com até 15 Caracteres!");
return false;
}
return true;
}

// fim da validação
</script>

<script language="javascript">
//MÁSCARA DE VALORES

function txtBoxFormat(objeto, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
} else {
nTecla = evtKeyPress.which;
if (nTecla == 8) {
return true;
}
}

sValue = objeto.value;

// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objeto.value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); }
else { // qualquer caracter...
return true;
}
}
else {
return true;
}
}
</script>
</head>

<body>
<form action='inserir_empresa.php' method='post' name='cadastro' id='cadastro' onSubmit='return confere(this)'>
<fieldset>
<legend> Dados da Empresa </legend>

<label>CNPJ:</label>
<input name='cnpj' type='text' id='cnpj' class='cnpj' maxlength='18' onkeypress="return txtBoxFormat(this,'99.999.999/9999-99', event);"><br />

<label>Raz&atilde;o Social:</label>
<input name='razsocial' type='text' class='razao' id='razsocial'><br />


<label>Insc.Est/Municipal:</label>
<input name='inscest' type='text' class='insc' id='inscest'><br />

<label>Ramo de Atividade:</label>
<input name='ramoativ' type='text' id='ramoativ' class='ramo'><br />

<label>Endere&ccedil;o:</label>
<input name='endereco' type='text' id='endereco' class='end2'><br />

<label>Bairro:</label>
<input name='bairro' type='text' id='bairro2' class='bairro'><br />

<label>Cidade:</label>
<input name='cidade' type='text' id='cidade'><br />

<label>CEP: </label>
<input name='cep' type='text' id='cep' class='cep' maxlength='9' onkeypress="return txtBoxFormat(this, '99999-999', event);"><br />

<label>UF: </label>
<input name='estado' type='text' id='estado' class='uf' maxlength='2'><br />

<label>Resp. Contato:</label>
<input name='contato' type='text' id='contato'> <br />

<label>Telefone:</label>
<input name='ddd' type='text' class='ddd' maxlength='2'>
<input name='telefone' type='text' id='telefone' maxlength='8'><br />

<label>Fax:</label>
<input name='dddfax' type='text' class='ddd' size='0' maxlength='2'>
<input name='fax' type='text' id='fax' maxlength='8'><br />

<label>E-mail:</label>
<input name='email' type='text' id='email' class='email3'><br />

<label>N&ordm; de Funcion&aacute;rios:</label>
<input name='qtdfun' type='text' id='qtdfun'><br />

<label>Tipo de Proposta:</label>
<input type='text' name='tipodeproposta' id='tipodeproposta'><br />

<label>Senha de Acesso:</label>
<input name='senha' type='password' id='senha' size='15' maxlength='15'>
<input name='enviar' type='submit' id='botao' value='Enviar'/>

</fieldset>
</form>


</body>
</html>[/codebox]

Editado por fercosmig
Adicionar tag CODE
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...