Olá, Estou tentando montar um formulario que some valores atumaticamente quando algum item é selecionado tenho um codigo aqui e funciona perfeitamente mas apenas com check, quando seleciona um campo ele soma e quando ele deseleciona e retira o valor, ok mas quando coloco radio buttons ele vai acrecentando valores e não alterando somando sem parar, se eu seleciono uma opção , depois mudo de ideia e seleciono outra no mesmo grupo do radio , fika os dois valores. gostaria de saber se algume pode me ajudar a fazer funcionar radio buttons também nesse codido obrigado.. segue o codigo <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);
}
// funcoes somas de checkds
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));
}
}
// -->
</script>
<form name=myform>
<div class="menu01 style2"> Estilo do site: <br />
<input type="checkbox" name=Steak value="300.00" onClick="this.form.total.value=checkChoice(this);">
Comum
(html, php,...) <br />
<input type= "checkbox" name=Chicken value="500.00" onClick="this.form.total.value=checkChoice(this);">
Flash (animado) <br />
<br />
Numero de links: (escolha apenas um) <br />
<input type="checkbox" name="Steak2" value="20.00" onclick="this.form.total.value=checkChoice(this);" />
Até
5 <br />
<input type="checkbox" name="Chicken2" value="25.00" onclick="this.form.total.value=checkChoice(this);" />
Até 7
<br />
<input type="checkbox" name="Steak22" value="30.00" onclick="this.form.total.value=checkChoice(this);" />
Até 10<br />
<input type="checkbox" name="Chicken22" value="35.00" onclick="this.form.total.value=checkChoice(this);" />
Até 15 <br />
<input type="checkbox" name="Steak222" value="50.00" onclick="this.form.total.value=checkChoice(this);" />
Mais de 15<br />
<br />
<br />
Formulários: <br />
<input type="checkbox" name="Steak3" value="20.00" onclick="this.form.total.value=checkChoice(this);" />
Contato<br />
<input type="checkbox" name="Chicken3" value="20.00" onclick="this.form.total.value=checkChoice(this);" />
Orçamento<br />
<input type="checkbox" name="Steak32" value="40.00" onclick="this.form.total.value=checkChoice(this);" />
Outros (personalizados) <br />
<br />
<br />
<br>
Total:
<input type="text" name="total" value="" size=6 readonly>
<input type=hidden name=hiddentotal value=0>
</p>
</div></form>
ninguém?
Se não conseguir ajeitar esse
alguém consegue fazer essa mesma função com outro codigo?
que consiga somar automaticamente usando radio e check?
obs:
o inico do cogido postado esta errado
não saiu o "< script ..."
subistitua para
<script LANGUAGE="JavaScript">
<!--
e assim continua ..... vlwww