[thelist] RE: Javascript Calculators

hup at telusplanet.net hup at telusplanet.net
Tue Apr 10 09:14:35 CDT 2001


>From: "Lauri Vain" <optima at hot.ee>
> changed to onsubmit to onchange and it works fine on
>http://www.tharapita.com/metric.htm. What I'm concerned 
>about, however, is that
>when I enter meters and the calculation will be made then the 
>meters will not be
>calculated out any more. In other words -- the metric calculation 
>comes first
>and is dominant about the feet calculation.

Your processData() function first tests to see if the Meter field is 
empty, if its not empty it calculates the respective Feet value. So, 
if you've already entered a value in the Meter field.. its not null  
and so overrides whatever you just entered in the Feet field.

You could try set the onFocus event .. and have it clear the other 
field. Ie., when they enter the Feet input box it clears the Metre 
box's value.. (I think this is kinda lame :)).

Or you could try adding parameters to your processData() 
function to distinguish which field is to be processed.. like 
<input type="text" name="length_meteres" 
processData(this.form, 'meter');">

And then process Data would run something along the lines of:
function processData(form, type)
     if (type == "meter" && form.length_meters.value > 0) {
	     form.length_feet.value=form.length_meters.value/(.3048)
	     }
     if (type == "feet" && form.length_feet.value > 0) {
	     form.length_meters.value=form.length_feet.value*(.3048)
	     }
///	etcetera . . .
}

Could be some bug in there, I just woke up and haven't tested it.. 
but you should be able to see where I'm going at least.

You could also take a look at my javascript calculators at:
http://www.floorheatsystems.com/conversions.cfm

I wrote about 6 calculators for that page (Area, Distance, 
Volume, Flow, Temperature, Pressure).. They're a little more 
flexible than what you're working on, but they might be helpful..

Later.




More information about the thelist mailing list