SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Mar 7, 2001, 17:18 #1
- Join Date
- Feb 2001
- Posts
- 67
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm trying to create a page that includes two javascript 'calories burned' type scripts on the same page. One covers calories burned while exercising, the other while working. Each uses the same script. If I run each one on separate pages, each works. But if I combine them on the same page, I get javascript errors. I've tried having both instances of the script on and having just one instance of the script with both forms.
The script used is:
Code:<SCRIPT LANGUAGE="JavaScript"> <!-- function FigureBURN(form, pounds, minutes, activity) { Weight = (pounds / 2.2) Time = minutes activity = document.BURN.activity.options[document.BURN.activity.selectedIndex].value form.calcval.value = (Math.round(Weight * activity)*(Time / 60)) } // --> </SCRIPT>
Code:<FORM NAME="BURN"> WEIGHT (pounds) <INPUT TYPE="TEXT" NAME="pounds" SIZE=5><br> MINUTES WORKED: <INPUT TYPE="TEXT" NAME="minutes" SIZE=5><BR> WORK <SELECT NAME="activity"> <OPTION selected value="4"> Bakery, general <OPTION value="3.5"> Carpentry, general </select> <br><br> <INPUT TYPE="BUTTON" name="calc" value="I burn" onClick="FigureBURNa(this.form,this.form.pounds.value, this.form.minutes.value,this.form.activity.value)"> <INPUT TYPE="TEXT" name="calcval" size=10> calories at work! </FORM>
Code:<FORM NAME="BURN"> WEIGHT (pounds) <INPUT TYPE="TEXT" NAME="pounds" SIZE=5><br> MINUTES EXERCISED <INPUT TYPE="TEXT" NAME="minutes" SIZE=5><BR> EXERCISE <SELECT NAME="activity"> <OPTION selected value="5"> Aerobics: low impact <OPTION value="7"> Aerobics: high impact </select> <BR><BR> <INPUT TYPE="BUTTON" name="calc" value="I burn " onClick="FigureBURN(this.form,this.form.pounds.value, this.form.minutes.value,this.form.activity.value)"> <INPUT TYPE="TEXT" name="calcval" size=10> calories at the gym. </FORM>
thanks
-
Mar 8, 2001, 13:02 #2
- Join Date
- Feb 2001
- Location
- Van down by the river
- Posts
- 254
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If the calculations are the same for working or exercising, you should be able to use one script. One problem I see is that you have two forms, both with the same name, and both containing a field named "calcval." JavaScript won't know which field you want to update. Give each form a unique name. You would then need to pass the name of the form to the function, so it knows which field to update. Let me know if that isn't the issue.
-
Mar 8, 2001, 16:13 #3
- Join Date
- Feb 2001
- Posts
- 67
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you! I had tried renaming several things, but had not renamed the forum. I have so much to learn.
Thanks again,
Suzanne
Bookmarks