1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
<html>
<head>
<title>My Untitled Document</title>
<script type="text/javascript">
function calcVals()
{
var
selects = document.getElementById('form1').getElementsByTagName('select'),
total = 0,
i;
for (i = 0; i < selects.length; i++) {
total += (isNaN(selects[i].value) ? 0 : Number(selects[i].value)) * (isNaN(selects[i].title) ? 0 : Number(selects[i].title));
}
document.getElementById('valTotal').value = ' ' + total.toFixed(2);
}
</script>
</head>
<body onLoad="calcVals()">
<? if ($_POST['send']){ ?>
<? echo floor($_POST['textfield']) ;?>
<? echo "<br>";?>
<? echo floor($_POST['textfield1']) ;?>
<? echo "<br>";?>
<? echo floor($_POST['textfield2']) ;?>
<? echo "<br>";?>
<? } ?>
updated
<form id="form1" name="form1" method="post" action="" >
$ 9.25
<select name="textfield" title="9.25" onChange="calcVals(this.form.form1)">
<option value="1" selected="selected">1</option>
<option value="2">2</option>
</select>
<br />
$ 12.25
<select name="textfield1" title="12.25" onChange="calcVals(this.form.form1)">
<option value="0" selected="selected">As gift</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<br />
$ -5.00
<select name="textfield2" title="-5.00" onChange="calcVals(this.form.form1)">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
<br />
<input type="text" readonly="" name="valTotal" id="valTotal" value="$0"/>
<input type="submit" name="send" value="SEND" />
</form>
</body>
</html> |
Partager