Help is javascript

Please register or login

Welcome to ScubaBoard, the world's largest scuba diving community. Registration is not required to read the forums, but we encourage you to join. Joining has its benefits and enables you to participate in the discussions.

Benefits of registering include

  • Ability to post and comment on topics and discussions.
  • A Free photo gallery to share your dive photos with the world.
  • You can make this box go away

Joining is quick and easy. Log in or Register now!

Dive-aholic

Contributor
Scuba Instructor
Messages
8,872
Reaction score
1,017
Location
North Florida - Marianna area
I'm trying to post a form on my website to calculate RMV. I have the form up, but when I click the calculate button nothing happens. It's probably something stupid, but I'm just starting out with javascript and can't figure it out.

Here's the code -

<head>
<script>
<!-- hide this script from old browsers
function RMV(form)
{
var p = parseFloat(form.PSI.value, 10);
var t = parseFloat(form.Time.value, 10);
var d = parseFloat(form.Depth.value, 10);
var c = parseFloat(form.Cylinder.value, 10);
var x = parseFloat(form.Rated.value, 10);
f = (c / x);
a = (p * f);
b = (a / t);
r = (b / d);
form.RMV.value = r;
}
<!-- done hiding from old browsers -->
</script>
</head>

<body>

<form>

<font color="#008000">Enter PSI used: <br /><input maxlength="4" size="4" name="p" />
</font>

<font color="#008000">Enter Time: <br /><input maxlength="2" size="2" name="t" />
</font>

<font color="#008000">Enter Depth: <br /><input maxlength="3" size="3" name="d" />
</font>

<font color="#008000">Enter Cylinder used: <br /><input maxlength="3" size="3" name="c" />
</font>

<font color="#008000">Enter Rated Pressure of Cylinder: <br /><input maxlength="4" size="4" name="x" />
</font>

<font color="#008000">Click this button to calculate your RMV:<br /><input onclick="RMV(this.form)" type="button" value="Calculate" name="calc" />
</font>
<font color="#008000">RMV is: <br /><input readonly size="3" name="RMV" />
</font>
</form>

Thanks for any help!
 
The problem is you have a function named RMV and an input named RMV... rename one of them and you'll be good to go :)

Also you need to reference your values properly, instead of form.PSI its form.p (look at the name attribute)
 
  • Like
Reactions: Jax
Here is a working copy:

<html>
<head>
<style type="text/css">

label {
color: #008000;
display: block;
}

</style>
<script type="text/javascript">
function calc_rmv(form)
{
var p = parseFloat(form.PSI.value, 10);
var t = parseFloat(form.Time.value, 10);
var d = parseFloat(form.Depth.value, 10);
var c = parseFloat(form.Cylinder.value, 10);
var x = parseFloat(form.Rated.value, 10);
f = (c / x);
a = (p * f);
b = (a / t);
r = (b / d);
form.RMV.value = r;
}
</script>
</head>

<body>

<form>
<label for="PSI">Enter PSI used:</label><input maxlength="4" size="4" name="PSI" /><br />

<label for="Time">Enter Time:</label><input maxlength="2" size="2" name="Time" /><br />

<label for="Depth">Enter Depth:</label><input maxlength="3" size="3" name="Depth" /><br />

<label for="Cylinder">Enter Cylinder used:</label><input maxlength="3" size="3" name="Cylinder" /><br />

<label for="Rated">Enter Rated Pressure of Cylinder:</label><input maxlength="4" size="4" name="Rated" /><br />

<label for="calc">Click this button to calculate your RMV:</label><input onclick="calc_rmv(this.form);" type="button" value="Calculate" name="calc" /><br />
<label for="RMV">RMV is:</label><input readonly size="3" name="RMV" />
</font>
</form>
</html>
 
I found that, but I'm not willing to pay $80 to see how well it works.


Thanks, sontek. I knew it was something simple. I kept looking it over but I guess I was just too tired to figure it out last night!

Is it up on your site, yet? :D
 
Not linked yet. I have some more changes I want to make to it to account for diving manifolded doubles or just a single cylinder. (Yes, can you believe some people still dive manifolded doubles!!! :shocked2: )
 
  • Like
Reactions: Jax
Cool Program Rob...wish I would have had it to use when I took the Deco course with that instructor a few months ago...he was a real pain.:D

 

Back
Top Bottom