Forum Moderators: open

Message Too Old, No Replies

Form Calculations

Using Square Root

         

CelticFC

3:05 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



Hi,

I am new to Javascript, and i am struggling to get a conversion form to work using Math.sqrt. Can someone please have a look at this code and see if you can spot any errors.

<form>
<script language="Javascript">

function calf (form){
var numb1=form.pressure.value;
var psi= Math.sqrt(numb1);
form.force.value = 0.0526 x form.flow.value * psi
}
</script>
<table width="271">
<tr>
<td>Flow(US Gallons) </td>
<td><input name="flow" type="text" id="flow" size="15"></td>
</tr>
<tr>
<td width="133">Pressure</td>
<td width="126"><input name="pressure" type ="text" id="pressure" size=15></td>
</tr>
<tr>
<td align="left"><input name="button2" type ="button" onClick="calf(this.form)" value="Calculate"></td>
</tr>
<tr>
<td height="24">Impact\Reaction Force </td>
<td><input name="force" type="text" id="force" size=15></td>
</tr>
</table>
</form>

Anyone who can solve this problem may just save what little hair i have left :0)

Any help or advice is greatly appreciated.

Thanks

ajkimoto

4:19 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



CelticFC,

Well, I noticed right off that in your calf() function, you have:

form.force.value = 0.0526 x form.flow.value * psi

when you should have

form.force.value = 0.0526 * form.flow.value * psi

(notice the 'x' that should be '*').

The script worked with the above change.

Hope this helps,

ajkimoto

CelticFC

4:56 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



Thanks ajkimoto

I cant believe i never noticed that!

What a ______ i am! (fill in the blanks yourself)

Thanks again!

CelticFC

4:58 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



One more question!

Does anyone know how to grey out the answer box or at least make it so that it is not accessable by the user?

Thanks

ajkimoto

5:31 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



CelticFC,

Well, there are a couple of approaches that you could take. The real problem is old browsers. If you only want to deal with more modern (say NS 6+, Mozilla, and IE 5+) you can use the readonly or disabled properties in the input. So:

<input type="text" disabled="disabled" value="">

or

<input type="text" readonly="readonly" value="">

If you use the disabled property, the box will automatically be grayed out. The readonly property will just make the textbox readonly without changing its appearance.

NS 4.7 doesn't understand the readonly and disabled so the objects will be read/write, but it does not generate any errors.

ajkimoto

CelticFC

5:53 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



Thanks again ajkimoto

you've been a great help!

CelticFC