I have a table which populates from a database the details about the selected golf course. In this table i have 18 rows, one for each hole. Each row populates data which resembles a golf scorecard and has an input for the score achieved on each hole.

I've figured out the code to calculate score and display on the first row, but how do I then do this for the other 17 holes

Table Code

```
echo "<tr>
        <td style='display:none;'><input type='number' class='form-control' name='holeID' id='hole".$row["holeID"]."' value=".$row["holeID"]." readonly tabindex='-1'></td>

        <td ><input type='number' class='form-control' name='holeNumber[]' id='hole".$row["holeNumber"]."' value=".$row["holeNumber"]." readonly tabindex='-1'></td>

        <td ><input type='number' class='text-center form-control' name='holePar[]' id='par".$row["holeNumber"]."' value=".$row["par"]." readonly tabindex='-1'></td>

        <td ><input type='number' class='text-center form-control strokeIndex' name='holeStrokeIndex[]' id='hole".$row["holeNumber"]."strokeIndex' value=".$row["strokeIndex"]." readonly tabindex='-1'></td>

        <td ><input type='number' class='text-center form-control strokesReceived' name='strokesReceived' id='hole".$row["holeNumber"]."strokesReceived' value='' readonly tabindex='-1'></td>

        <td ><select class='form-control scoreInput' id='scoreInputHole".$row["holeNumber"]."' name='scoreInput' >
    <option value='' disabled selected hidden>Input Score..</option>
    <option value='1'>1</option>
    <option value='2'>2</option>
    <option value='3'>3</option>
    <option value='4'>4</option>
    <option value='5'>5</option>
    <option value='6'>6</option>
    <option value='7'>7</option>
    <option value='8'>8</option>
    <option value='9'>9</option>
    <option value='NR'>NR</option>  
</td>

        <td ><input type='number' class='text-center form-control pointsScored' name='pointsScored' id='hole".$row["holeNumber"]."points' value='' readonly tabindex='-1'></td>

        </tr>";

```

Code for score calc

```
 $(document).on('change','#scoreInput',function(){
        alert($('#scoreInput :selected').val()+ " shots");

        var score = $('#scoreInput :selected').val();

        var par = document.getElementById('par1').value;

        var pointsScored = document.getElementsByName('pointsScored');

        alert ("Par " + par);

        var strokesReceived = document.getElementById('hole1strokesReceived').value;

    alert (strokesReceived + " strokes received");

    points = (parseFloat(par) + parseFloat(strokesReceived)) - parseFloat(score) + parseFloat(2);

    if(points < 1 || score == "NR"){
                    points = 0
                }

            alert (points + " points");

                pointsScored[0].setAttribute('value',points);

            });

```

Ok, i have changed code to below and each line is working as expected, referencing the correct values, I'm now having an issue getting the pointsScored to show , error is 

Uncaught TypeError: pointsScored.setAttribute is not a function

or

adminEventScoreEntry.php?id=1:837 Uncaught TypeError: $(...).closest(...).find(...).setAttribute is not a function

```
 $(document).on('change','.scoreInput',function(){

                var score = $(this).children('option:selected').val();

                var par = $(this).closest('tr').find('.par').val();

                var pointsScored = $(this).closest('tr').find('.pointsScored');

                var strokesReceived = $(this).closest('tr').find('.strokesReceived').val();

                var points = (parseFloat(par) + parseFloat(strokesReceived)) - parseFloat(score) + parseFloat(2);

                console.log ("Score is "+score);
                console.log ("Par is "+par);
                console.log (strokesReceived + " strokes received");

                if(points < 1 || score == "NR"){
                    points = 0

                console.log (points +" points scored");

                $(this).closest('tr').find('.pointsScored').setAttribute('value', points);

                } else {

                    console.log (points +" points scored");
                    $(this).closest('tr').find('.pointsScored').setAttribute('value', points);
                }

            });
        });

```