Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bom, o que eu preciso é mais ou menos isso...
tenho um campotxt e um menu select... encima do campotxt tenho o nome dele e no menu select as opções para ele... ao selecionar uma destas opções o nome muda, e queria por, ao selecionar o CPF mudasse o nome e aplicasse também a máscara....
A parte do select e mudar o nome que fica encima, com a ajuda de vocês consegui fazer....
segue o código...
<?php error_reporting(E_ALL); include ("conexao.php"); $sql_categoria = "select * from categori"; $consulta_categoria = ibase_query($conexao, $sql_categoria); $sql_editora = "select * from editora"; $consulta_editora = ibase_query($conexao, $sql_editora); ?><html><body><script> function formataCPF(campo) { if (campo.value.length == 3) { campo.value = campo.value + "."; } if (campo.value.length == 7) { campo.value = campo.value + "."; } if (campo.value.length == 11) { campo.value = campo.value + "-"; } }</script><script> function formataTELEFONE(campo) { if (campo.value.length == 2) { campo.value = "(" + campo.value + ")"; } if (campo.value.length == 8) { campo.value = campo.value + "-"; } } </script><script>function mostra(select) { var sel = parseInt(select.value); var texto; switch (sel) { case 1: texto = 'Nome'; break; case 2: texto = 'CPF'; break; case 3: texto = 'Telefone'; break; } document.getElementById('print_nome').innerHTML = texto;}</script><a href="cadcli.php">Cadastrar</a><form action="livros.php" method="post" name="form1" target="livros" id="form1"> <table width="955" border="0"> <tr> <td rowspan="2" ><br /> <br /></td> <td width="555" height="21" id="print_nome"><?php echo "<b>"; ?>Nome<br /><label> </label></td> <td width="142" rowspan="2">Procurar por:<br /> <label> <select name="procura" onChange="mostra(this)"> <option value="1">Nome</option> <option value="2">CPF</option> <option value="3">Telefone</option> </select> </label></td> <td width="124" rowspan="2">:<br /> <label></label></td> <td width="116" rowspan="2">:<br /> <label></label></td> </tr> <tr> <td><input name="campotxt" type="text" size="80" /></td> </tr> </table> <table width="200" border="0"> <tr> <td><label> <input type="submit" name="Submit" value="Procurar" /> </label></td> <td> </td> <td><label> <input type="reset" name="Submit2" value="Limpar" /> </label></td> </tr> </table></form>
Quando selecionar o CPF por exemplo, já queria aplica no campotxt a máscara do CPF.. é possível isso?
a máscara uso assim
<script> function formataCPF(campo) { if (campo.value.length == 3) { campo.value = campo.value + "."; } if (campo.value.length == 7) { campo.value = campo.value + "."; } if (campo.value.length == 11) { campo.value = campo.value + "-"; } }</script>
e uso assim
onKeyUp="formataCPF(this)"
Tentei colocar dentro do Case, mas não funcionou não.. se bem que acho que fiz errado... hehehe
Valeu
Carregando comentários...