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

Counting Text Fields


Guest Chris Newman

Pergunta

Guest Chris Newman

Hi,

first this has to be one of the best Script forums I have seen on the web. PARABENS pessoal do SCRIPTBRASIL.

Now on to my question:

I have 10 textfields in my HTML page. Also I have another one that will count how many of the 10 are filled out. So if i fill out 4 textfields the number on the total will be 4. I need this to happen dynamically so that the total changes everytime you fill out the textfield.

link of my idea: http://www.4by2.com.br/teste.htm

I know this is done by Javascript but i don´t know how to program .... any help will be greatly appreciated. I am willing to pay for help if necessary.

Thanks Chris Newman

Now to my attempt on Português

Ola pessoal, primeiro parabens pelo site... super bem feito... já esta no meus favoritas!

Agora a pergunta.... eu tenho 10 campos de texto na minha página HTML e também mais um que vai servir para mostrar o total dos capmos preenchidos. Se a pessoa complete 4 campos ... o número vai ser 4. etc. Aqui é um link para entender melhor:

http://www.4by2.com.br/teste.htm

Qualquer resposta seria bem recebido. Posso até pagar para uma resposta!

Obrigado... e desculpe o meu português

um abraço Chris Newman

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Oi Chris Newman.

Você pode obter a quantidade de campos que quer verificar, fazer um for e dentro deste for testar com um if se a propriedade value.length do campo correspondente é igual a zero ele está vazio.

O exemplo abaixo deve funcionar.

Hi Chris Newman,

You can get the quantity of elements on your form and make for and verify with if the propriety value.length of evrybody elements. If propriety it's iqual a zero, this element don't have content, so complete the last input with result the sum at varible counter in a for...

The example below must function.

<html>

<head>

<script language="Javascript">

<!--

    function  countInputs(){

          var sizeInputs = document.forms['0'].elements.length; //obtém a quantidade de elementos

          var j = 0;

         

            for(i=0; i < (sizeInputs-1); i++)

                  if(document.forms['0'].elements.value.length > 0)

                      j++;

         

          document.forms['0'].output.value = j;

    }

//--></script>

</head>

<body>

<form method="POST" action="you_link.php" name="form_one">

  <input type="text" name="input_1" size="45" onblur="countInputs()">

  <input type="text" name="input_2" size="45" onblur="countInputs()">

  <input type="text" name="input_3" size="45" onblur="countInputs()">

  <input type="text" name="output" size="4" readonly>

</form>

</body>

</html>

my English is an excrement, does not repair!

Abraço e seja bem-vindo!

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,2k
    • Posts
      651,9k
×
×
  • Criar Novo...