zepunk 22 de nov. de 2006
De qual forma você quer fazer ??
JavaScript ou Enviando para o servidor ??
em javaScript vc pode fazer assim
<HTML>
<HEAD>
<script>
function calcular()
{
var text1 = parseFloat(document.getElementById("campo1").value);
var text2 = parseFloat(document.getElementById("campo2").value);
document.getElementById("total").value = text1 + text2;
}
</script>
</HEAD>
<BODY>
<input type= text id= "campo1" >
<input type= text id= "campo2" >
<input type= text id= "total" >
<input type= button value= "clique aqui" onClick= "calcular();" >
</BODY>
</HTML>
marciobarroso 22 de nov. de 2006
Esse tb está funcionando … mais uma opção.
[]'s
& lt ; html & gt ;
& lt ; head & gt ;
& lt ; script & gt ;
function $ ( id ) {
return document . getElementById ( id );
}
function A ( id ) {
return document . getElementById ( id ). value ;
}
function sum () {
var x ;
var regex = /^[ 0-9 ] { 1 , 5 }$ / ;
var total = 0 ;
var campos = new Array ( "data1" , "data2" , "data3" , "data4" , "data5" );
for ( x in campos ) {
if ( regex . test ( A ( campos [ x ] )) ) {
total += parseInt ( A ( campos [ x ] ));
}
$ ( 'total' ). value = total ;
}
}
& lt ; / script & gt ;
& lt ; / head & gt ;
& lt ; body & gt ;
& lt ; form & gt ;
& lt ; input class = "input" name = "data1" id = "data1" size = "10" type = "text" & gt ; < br >
& lt ; input class = "input" name = "data2" id = "data2" size = "10" type = "text" & gt ; < br >
& lt ; input class = "input" name = "data3" id = "data3" size = "10" type = "text" & gt ; < br >
& lt ; input class = "input" name = "data4" id = "data4" size = "10" type = "text" & gt ; < br >
& lt ; input class = "input" name = "data5" id = "data5" size = "10" type = "text" & gt ; < br >
& lt ; input class = "input" name = "total" id = "total" size = "10" type = "text" readonly = "true" & gt ; < br >
& lt ; input type = button value = "Somar" onclick = "sum();" & gt ; & nbsp & lt ; input type = "reset" value = "limpar" /& gt ;
& lt ; / form & gt ;
& lt ; / body & gt ;