Page 1 of 2

Calculate without submit

Posted: Mon Nov 07, 2005 10:04 pm
by facets
Is it possible to calculate maths problems (from text input) without using submit.
perhaps by focus() ?

Posted: Mon Nov 07, 2005 10:17 pm
by feyd
calculate, yes.. focus() not specifically...

Posted: Mon Nov 07, 2005 10:35 pm
by facets
any hints or examples?
.. i've googled to no avail.

Posted: Mon Nov 07, 2005 10:40 pm
by feyd
what are you specifically trying to do?

Posted: Mon Nov 07, 2005 10:46 pm
by facets
just a simple x * y = z

so :

text input 1 * text input 2 display answer.

without submit. I think it may use onChange=function(this) ??

Posted: Mon Nov 07, 2005 10:47 pm
by feyd

Posted: Mon Nov 07, 2005 10:50 pm
by facets
without the calulate button :)

Posted: Mon Nov 07, 2005 10:50 pm
by feyd
it's not a submission..

Posted: Mon Nov 07, 2005 10:53 pm
by facets
sorry, bad phrasing. without user interaction.

Posted: Mon Nov 07, 2005 11:29 pm
by ryanlwh
onKeyUp then?

Posted: Mon Nov 07, 2005 11:35 pm
by RobertGonzalez
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.

Posted: Tue Nov 08, 2005 12:00 am
by facets
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/

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>

Posted: Tue Nov 08, 2005 1:05 am
by RobertGonzalez
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.

Posted: Tue Nov 08, 2005 1:09 am
by facets
with no form tag how do you address the variables?

var inp = document.ccForm.inpt.value
var inp2 = document.ccForm.inpt2.value

It's actually a PHP form and most of the page is within the 'master' form tags.

Posted: Tue Nov 08, 2005 1:12 am
by RobertGonzalez
Why not use the master form tag name? Maye post some more code so we can see what is happening. I am hitting the sack right now. I'll try to take a look tomorrow.