Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Creating a Result Sheet using Javascript

    I run a website for a skittle league and am looking to create a form to allow teams to sumbit results on line.

    I'm not an expert on Javascript, the code I've created so far allows the user to enter the player name and score for one team and calcutate the total. However, I'm having problems duplicating this for a second team, and would like to remove the Get Total button (i.e. Auto Calculate total).

    Can anyone advise how I can do this.

    The Code I have so far is

    <html>
    <head>
    <script type="text/javascript" language="javascript">
    function getTotalH1(oForm)
    {
    var field, i = 0, total = 0, els = oForm.elements;
    var fieldnames = ['PSH1' , 'PSH2' , 'PSH3' , 'PSH4' , 'PSH5'];
    for (i; i < fieldnames.length; ++i)
    {
    field = els[fieldnames[i]];
    if (field.value != '' && isNaN(field.value))
    {
    alert('Please enter a valid number here.')
    field.focus();
    field.select();
    return '';
    }
    else total += Number(field.value);
    }
    return ' ' + total;
    }
    </script>
    </head>
    <body>
    <form>
    <div align="center"><table border="0" cellpadding="2" cellspacing="0" width="305">
    <col width="250" align="left">
    <col width="42" align="center">
    <tr>
    <td><input type="text" name="PNH1" size="35"> </td>
    <td><input id="PSH1" type="text" name="PSH1" value="" size="4"></td>
    </tr>
    <tr>
    <td><input type="text" name="PNH2" size="35"></td>
    <td><input id="PSH2" type="text" name="PSH2" value="" size="4"></td>
    </tr>
    <tr>
    <td><input type="text" name="PNH3" size="35"></td>
    <td><input id="PSH3" type="text" name="PSH3" value="" size="4"></td>
    </tr>
    <tr>
    <td><input type="text" name="PNH4" size="35"></td>
    <td><input id="PSH4" type="text" name="PSH4" value="" size="4"></td>
    </tr>
    <tr>
    <td><input type="text" name="PNH5" size="35"></td>
    <td><input id="PSH5" type="text" name="PSH5" value="" size="4"></td>
    </tr>
    <tr>
    <td><input type="button" value="Get Total" onclick="total.value=getTotalH1(this.form)" />
    <input type="reset" /></td>
    <td><input id="total" type="text" name="totalh1" value="" readonly="readonly" size="4"></td>
    </tr>
    </table></div>
    <br><br>
    </form>
    </body>
    </html>

    thanks

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    I don't know enough about 'skittle' to know what you need.

    what does the first and second column of the 5 rows represents?
    Team name? Score and format of score??)

    What is the non-working part or do you need to duplicate the 2x5 display?


    BTW: You should surround your script with [ code] and [ /code] tags (without the spaces)
    to make it easier for the forum members to read and comment upon.
    You can edit your 1st post to see the effect.

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've been working on a form using scripts I've found and have created the following form which can be found via the following link (thought it would be easier rather than pasting in the code)

    http://www.stroudskittles.co.uk/test/scorecard.html

    I've added hints to explan what needs to be entered

    As you will see there are two halves with 5 players per team. For each half the Player names and Scores can be entered, with the totals added automatically. What am looking to do is add together the totals for the two halves without the need to click on the link.

    Can anyone advise if this is possible

    Thanks

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    In you function calls for the onBlur events, for example
    Code:
    function calcA1() {
      AS1 = document.clock.AS1.value;
      AS2 = document.clock.AS2.value; 
      AS3 = document.clock.AS3.value;
      AS4 = document.clock.AS4.value;
      AS5 = document.clock.AS5.value;
      document.clock.TotalA1.value = (AS1 * 1) + (AS2 * 1) + (AS3 * 1) + (AS4 * 1) + (AS5 * 1);
      addNumbersA();
    }
    Try adding the call in RED

  • #5
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Unfortunately it doesn't appear to work

    Currently on the sampe Result card (which can be found at

    http://www.stroudskittles.co.uk/test/scorecard.html

    I can add the scores for each team for each half (i.e. First Half Away Scores - AS1 + AS2 + AS3 + AS4 + AS5 = A1, then Second Half Aways Scores - AS6 + AS7 + AS8 + AS9 + AS10 = A2) then automatically Generate a Total for each team for each half.

    To obtain the overall total (i.e. A1 + A2) the user needs to Click on the Button. I am hoping I can create this automatically.

    This then removes the possibilities of error when people add up numbers.

    Any assistance would be appreciated

    Many Thanks

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by gazza3665 View Post
    Unfortunately it doesn't appear to work

    ...
    What error did you get?
    What happened?

    The link you posted does not contain the change I suggested.

  • #7
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Many Thanks for your Help it is working well

    Form uploaded as http://www.stroudskittles.co.uk/scorecard1.html

    Now just have to look at how to format the email

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by gazza3665 View Post
    Many Thanks for your Help it is working well

    Form uploaded as http://www.stroudskittles.co.uk/scorecard1.html

    Now just have to look at how to format the email
    You're most welcome.
    Happy to help.
    Good Luck!


    BTW: The last post has a broken link so we cannot see what you changed to make it work.

  • #9
    New Coder
    Join Date
    Jan 2011
    Posts
    66
    Thanks
    10
    Thanked 5 Times in 5 Posts
    I think you just need to put the test folder back in the url.

    http://www.stroudskittles.co.uk/test/scorecard1.html

  • #10
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts
    You get a 'NaN' when the entries are made to only one of the 4 sections.
    It becomes correct when values are entered into top & bottom sections.

    You might want to check the fields for a blank ('' string) and set to 0 (zero) when found.
    You could also test for the NaN error and change the field to 0 (zero)

    Only a suggestion ...

    Good Luck!

  • #11
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion, I was wondering how to remove the NaN and have now done so, have added the value option and it works

    http://www.stroudskittles.co.uk/test/scorecard3.html

    Thanks for your help

  • #12
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by gazza3665 View Post
    Thanks for the suggestion, I was wondering how to remove the NaN and have now done so, have added the value option and it works

    http://www.stroudskittles.co.uk/test/scorecard3.html

    Thanks for your help
    Better ... Final question: What do the [?] areas represent?
    Reference to a pop-up help display or field description?

  • #13
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    They are Help Tips so people know what to enter in the boxes

    A useful peice of Javascript I found which gives people some guidance

  • #14
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    On my Result Card form I'm trying to add a box which automatically creates the points.

    I know I need to use the if and else if command

    What I'm trying to achieve is

    If TotalH1 > TotalA1 Value = 2
    else if TotalH1 = TotalA1 Value = 1
    else TotalH1 < TotalA1 Value = 0

    Can anyone help on making a script

    The link for the Card is http://www.stroudskittles.co.uk/test/scorecard.html

  • #15
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Code:
    if (TotalH1 > TotalA1) {Value = 2}
    else if (TotalH1 == TotalA1) {Value = 1}
    else if (TotalH1 < TotalA1) {Value = 0}

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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