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

(Resolvido) Formulário Orçamento com Soma


EdgarGalluzzo

Pergunta

Boa tarde meu povo, acabei de me cadastrar neste fórum para tirar uma dúvida! Não sei se vou contra às regras, e peço desculpas se estiver! :rolleyes:

Mas vamos à dúvida!

Estou criando um formulário para orçamento da gráfica onde trabalho, sendo que todos os campos contém um valor pré-determinado que será somado no final da página.

Porém, neste exemplo que vou postar abaixo, não consigo fazer aparecer mais do que 1 checkbox com o valor. :wacko:

<html>
<head>
</head>
<body>


<form>
&lt;script LANGUAGE="JavaScript">
<!--
function checkChoice(whichbox) {
with (whichbox.form) {
if (whichbox.checked == false)
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);
else
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);
return(formatCurrency(hiddentotal.value));
   }
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return ("R$" + num + "." + cents);
}
// -->
</script>
<p>Teste clicando aqui <INPUT TYPE="checkbox" ONCLICK="document.all.mostraBox.style.display = 

(document.all.mostraBox.style.display == 'none') ? '' : 'none'; document.all.mostraTexto.style.display = 

(document.all.mostraTexto.style.display == 'none') ? '' : 'none'">
<BR>
<font style="display:none" color="black" id="mostraTexto"> campo:</font> 

<INPUT TYPE="checkbox" STYLE="display:none" ID="mostraBox" name="campo1" value="10.00" 

onClick="this.form.total.value=checkChoice(this);">



<br>
Total: <input type="text" name="total" value="" size=6 readonly><input type=hidden name=hiddentotal value=0>
</form>
</body>
</html>

Se vocês souberem me ajudar, ficarei grato! :lol:

Obrigado por enquanto! :rolleyes:

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Eu mesmo me ajudei! kkkkkkkkkkkkkk

Vou postar o q eu fiz!

<html>

<head>

</head>

<body>

<form>

<script LANGUAGE="JavaScript">

<!--

function checkChoice(whichbox) {

with (whichbox.form) {

if (whichbox.checked == false)

hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);

else

hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);

return(formatCurrency(hiddentotal.value));

}

}

function formatCurrency(num) {

num = num.toString().replace(/\$|\,/g,'');

if(isNaN(num)) num = "0";

cents = Math.floor((num*100+0.5)%100);

num = Math.floor((num*100+0.5)/100).toString();

if(cents < 10) cents = "0" + cents;

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)

num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

return ("R$" + num + "." + cents);

}

// -->

</script>

<INPUT TYPE="checkbox" ONCLICK="document.all.mostraBox.style.display = (document.all.mostraBox.style.display == 'none') ? ''

: 'none'; document.all.mostraTexto.style.display = (document.all.mostraTexto.style.display == 'none') ? '' : 'none';

document.all.mostraBox2.style.display = (document.all.mostraBox2.style.display == 'none') ? '' : 'none';

document.all.mostraTexto2.style.display = (document.all.mostraTexto2.style.display == 'none') ? '' : 'none';

document.all.mostraBox3.style.display = (document.all.mostraBox3.style.display == 'none') ? '' : 'none';

document.all.mostraTexto3.style.display = (document.all.mostraTexto3.style.display == 'none') ? '' : 'none'">

<BR>

<font style="display:none" color="black" id="mostraTexto"> campo:</font>

<INPUT TYPE="checkbox" STYLE="display:none" id="mostraBox" name="campo1" value="10.00"

onClick="this.form.total.value=checkChoice(this);">

<font style="display:none" color="black" id="mostraTexto2"> campo:</font>

<INPUT TYPE="checkbox" STYLE="display:none" id="mostraBox2" name="campo1" value="10.00"

onClick="this.form.total.value=checkChoice(this);">

<font style="display:none" color="black" id="mostraTexto3"> campo:</font>

<INPUT TYPE="checkbox" STYLE="display:none" id="mostraBox3" name="campo1" value="10.00"

onClick="this.form.total.value=checkChoice(this);">

<br><br><div>

Total: <input type="text" name="total" value="" size=6 readonly><input type=hidden name=hiddentotal value=0>

</form>

</body>

</html>

[/quote]

Para acrecentarem mais campos, basta adicionar quantas vezes for necessário esta linha de código abaixo:

[code]

<INPUT TYPE="checkbox" ONCLICK="document.all.mostraBox.style.display = (document.all.mostraBox.style.display == 'none') ? '' 

: 'none'; document.all.mostraTexto.style.display = (document.all.mostraTexto.style.display == 'none') ? '' : 'none'; 

document.all.mostraBox2.style.display = (document.all.mostraBox2.style.display == 'none') ? '' : 'none'; 

document.all.mostraTexto2.style.display = (document.all.mostraTexto2.style.display == 'none') ? '' : 'none'; 

document.all.mostraBox3.style.display = (document.all.mostraBox3.style.display == 'none') ? '' : 'none'; 

document.all.mostraTexto3.style.display = (document.all.mostraTexto3.style.display == 'none') ? '' : 'none'">
Modificando o número do mostraBox# e mostraTexto#, referente ao ID do checkbox, exemplo:
<INPUT TYPE="checkbox" ONCLICK="document.all.mostraBox3.style.display = (document.all.mostraBox3.style.display == 'none') ? '' 

: 'none'; document.all.mostraTexto3.style.display = (document.all.mostraTexto3.style.display == 'none') ? '' : 'none'; 

document.all.mostraBox3.style.display = (document.all.mostraBox3.style.display == 'none') ? '' : 'none'">

<font style="display:none" color="black" id="mostraTexto3"> campo:</font> 

<INPUT TYPE="checkbox" STYLE="display:none" id="mostraBox3" name="campo1" value="10.00" 

onClick="this.form.total.value=checkChoice(this);">

Facinho e eu aqui quase me enforcando! kkk :wacko:

Abraçoo

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