Calculate without submit

JavaScript and client side scripting.

Moderator: General Moderators

facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Calculate without submit

Post by facets »

Is it possible to calculate maths problems (from text input) without using submit.
perhaps by focus() ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

calculate, yes.. focus() not specifically...
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

any hints or examples?
.. i've googled to no avail.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what are you specifically trying to do?
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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) ??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

without the calulate button :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's not a submission..
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

sorry, bad phrasing. without user interaction.
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

onKeyUp then?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply