Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Small Form, Big problems 1

Status
Not open for further replies.

JavaUser123

Technical User
Apr 22, 2007
8
GB
Hi
I Have A Small Form That Has Big Problems
in The Code I Need it so that MHR x Workout = Target BPM HR
Can Someone Help? I Have No Problem With The Contents of the first fieldset
Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function a_minus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.ans.value=c
}
function c_times_d(form) {
c=eval(form.c.value)
d=eval(form.d.value)
e=c*d
form.ans.value=c
}
</SCRIPT>
</head>
<body> <fieldset>
<FORM name="formx">
Age &nbsp;&nbsp;
    <input type=text size=4 value=12 name="b"> <br>
    <input type=hidden value=220 name="a">
MHR <input type=text name="ans">
<input type="button" value="Calculate MHR" onClick="a_minus_b(this.form)">   
</FORM> </fieldset>
<form> <fieldset>
MHR  <input type=text name="c"> <br>
Workout <input type=text name="d"> <br>
Target BPM HR <input type=text name="ans">
<input type="button" value="Find Target BPM" onClick="c_times_d(this.form)">
</form>
</body>
</html>
 
Well, I don't know if it actually answers your question - but here is the same code as you posted, but validating (all the nodes are in the right place etc).

Both buttons seem to do things, and hopefully with the code represented more consistently, you'll have no problems with further modification.
Code:
<html>
<head>
<script language="javascript">
function a_minus_b(form) {
	var a = form.a.value;
	var b = form.b.value;
	var c = a-b;
	form['ans'].value=c;
}
function c_times_d(form) {
	var c = form.c.value;
	var d = form.d.value;
	var e = c*d;
	form['ans'].value=e;
}
</script>
</head>
<body>
	<form onsubmit="return false">
		<fieldset>
			<input type="hidden" value="220" name="a">
			<div>Age <input type="text" size="4" value="12" name="b"/></div>
			<div>MHR <input type="text" name="ans"/></div>
			<input type="button" value="Calculate MHR" onclick="a_minus_b(this.form)">
		</fieldset>
	</form>
	<form onsubmit="return false">
		<fieldset>
			<div>MHR <input type="text" name="c"/></div>
			<div>Workout <input type="text" name="d"/></div>
			<div>Target BPM HR <input type="text" name="ans"/></div>
			<input type="button" value="Find target BPM" onclick="c_times_d(this.form)"/>
		</fieldset>
	</form>
</body>
</html>
Let us know how you go,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top