forms

G

Greg

If i have a form and I want get the total and display it in a text field how
can i do it i have tried have just <form name="myform"> but it stays there
for about a second and then clears the form. If i have <form name="myform"
method="post"> I get an error message and if i use <form name="myform"
method="get"> its the same as <form name="myform">
 
M

McKirahan

Greg said:
If i have a form and I want get the total and display it in a text field how
can i do it i have tried have just <form name="myform"> but it stays there
for about a second and then clears the form. If i have <form name="myform"
method="post"> I get an error message and if i use <form name="myform"
method="get"> its the same as <form name="myform">


What do you mean by "get the total"?

Do you just want to use JavaScript to do a calculation?

Will this help? Watch for word-wrap.

<html>
<head>
<title>total.htm</title>
<script type="text/javascript">
function total() {
var form = document.myform;
var tot1 = form.my1.value;
if (tot1 == "") return;
var tot2 = form.my2.value;
if (tot2 == "") return;
form.tot.value = parseInt(tot1,10) + parseInt(tot2,10);
}
</script>
<style type="text/css">
..rite { text-align:right }
..tots { text-align:right; background-color:#EEEEEE }
</style>
</head>
<body onload="document.myform.my1.focus()">
Enter number and press Tab to calculate Total.
<br><br>
<form name="myform">
<input type="text" name="my1" size="8" maxlength="7"
value="0" class="rite" onchange="total()">
&nbsp;<b>+</b> &nbsp;
<input type="text" name="my2" size="8" maxlength="7"
value="0" class="rite" onchange="total()">
&nbsp;<b>=</b> &nbsp;
<input type="text" name="tot" size="8" maxlength="9"
value="0" class="tots" readonly>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top