Calculate without submit
Moderator: General Moderators
Calculate without submit
Is it possible to calculate maths problems (from text input) without using submit.
perhaps by focus() ?
perhaps by focus() ?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
http://javascript.internet.com/calculat ... olver.html may be of interest..
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Check out My Broker Team, a web site I set up for a client. One of their calculators does what you want.
By tabbing from text box to text box the final value is calculated immediately on each tab.
By tabbing from text box to text box the final value is calculated immediately on each tab.
I got this going on a seperate page but how could I do it without forms?
The page is a form and therefore nested forms are a no no.
Any ideas/
The page is a form and therefore nested forms are a no no.
Any ideas/
Code: Select all
<script>
function calc() {
var inp = document.ccForm.inpt.value
var inp2 = document.ccForm.inpt2.value
var outp = 0
outp = inp * inp2
document.ccForm.outpt.value = outp
}
</SCRIPT>
<FORM ACTION=\"#\" NAME=\"ccForm\">
<INPUT TYPE=TEXT NAME=\"inpt\" SIZE=10 VALUE=\"2.9\" ONCHANGE=\"calc()\">
<INPUT TYPE=TEXT NAME=\"inpt2\" SIZE=10 VALUE=\"2.9\" ONCHANGE=\"calc()\">
<INPUT TYPE=TEXT NAME=\"outpt\" SIZE=10 DISABLED>
<BR><BR>
</FORM>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
When you say the page is a form do you mean that you are developing a .NET page? Even if you are not you can just drop the opening and closing <form> tags and use the inputs the way they are. You can even get rid of the form tags altogether and just use the inputs, although I am not sure that this is XHTML compliant.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA