SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    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>
    I'll cut out most of the options in the forms to save space here. The forms used are

    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>
    and

    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>
    Can anyone suggest a way to make this work on the same page?

    thanks

  2. #2
    I believe you have my stapler. scrubz's Avatar
    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.

  3. #3
    SitePoint Enthusiast
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •