CTalkobt.Net




Programming Newsgroup Tips & Tricks CubeCart Stuff
Forms
Subject: Forms
Date: Sun, 18 Sep 2005 21:38:29 -0500
Newsgroups: comp.lang.javascript
"Greg" <none> wrote in message news:432e07dd@dnews.tpgi.com.au...
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>