Forum Moderators: open
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
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
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