Jump to content

How Can I Get A Running Total Of Form Input Id's


wright67uk

Recommended Posts

How can I edit my code so that the input box with the id "totalparscore" diplays a running total of the input boxes with the id's;

hole1result, hole2result .............through to hole9result ?

 

I have made an attempt below, but could really do with some help.

 

 

 

 

<html> <head> <title>Text Summation</title>

 

<style type="text/css">

input[type=text] {width: 40px}

</style>

 

<script type="text/javascript">

 

function calc(A,B,SUM)

{

var one = Number(A);

if (isNaN(one)) { alert('Invalid entry: '+A); one=0; }

var two = Number(document.getElementById(B).value);

if (isNaN(two)) { alert('Invalid entry: '+B); two=0; }

document.getElementById(SUM).value = one - two;

}

 

</script>

 

<!------------------------------------------------------>

<!------------I NEED HELP WITH THE CODE BELOW ---------->

<!------------------------------------------------------>

 

<script language="javascript" type="text/javascript">

function addition(){

c= document.getElementById("hole1result".value);

d= document.getElementById("hole2result".value);

e= document.getElementById("hole3result".value);

f= document.getElementById("hole4result".value);

g= document.getElementById("hole5result".value);

h= document.getElementById("hole6result".value);

i= document.getElementById("hole7result".value);

j= document.getElementById("hole8result".value);

k= document.getElementById("hole9result".value);

t=c+d+e+f+g+h+i+j+k;

document.getElementById("totalparscore").value=t;

}

</script>

 

<!-------------------------------------------------------->

 

</head>

<body>

 

<form name="form" action="addup5.php" method="post" >

 

1)Score: <input type="text" name="sum1" id="hole1A" value="" onchange="calc(this.value,'hole1B','hole1result')" />

Par: <input name="sum2" readonly value="2" id="hole1B" onchange="calc(this.value,'hole1A','hole1result')" />

Par Score: <input name="sum" value="" id="hole1result" readonly style="border:0px;"> <br>

 

2)Score: <input name="sum1" id="hole2A" value="" onchange="calc(this.value,'hole2B','hole2result')" />

Par: <input name="sum2" readonly value="5" id="hole2B" onchange="calc(this.value,'hole2A','hole2result')" />

Par Score: <input name="sum2T" value="" id="hole2result" readonly style="border:0px;"> <br>

 

3)Score: <input name="sum1" id="hole3A" value="" onchange="calc(this.value,'hole3B','hole3result')" />

Par: <input name="sum2" readonly value="5" id="hole3B" onchange="calc(this.value,'hole3A','hole2result')" />

Par Score: <input name="sum3" value="" id="hole3result" readonly style="border:0px;"> <br>

 

4)Score: <input name="sum1" id="hole4A" value="" onchange="calc(this.value,'hole4B','hole4result')" />

Par: <input name="sum2" readonly value="5" id="hole4B" onchange="calc(this.value,'hole4A','hole4result')" />

Par Score: <input name="sum4" value="" id="hole4result" readonly style="border:0px;"> <br>

 

5)Score: <input name="sum1" id="hole5A" value="" onchange="calc(this.value,'hole5B','hole5result')" />

Par: <input name="sum2" readonly value="5" id="hole5B" onchange="calc(this.value,'hole5A','hole5result')" />

Par Score: <input name="sum5" value="" id="hole5result" readonly style="border:0px;"> <br>

 

6)Score: <input name="sum1" id="hole6A" value="" onchange="calc(this.value,'hole6B','hole6result')" />

Par: <input name="sum2" readonly value="5" id="hole6B" onchange="calc(this.value,'hole6A','hole6result')" />

Par Score: <input name="sum6" value="" id="hole6result" readonly style="border:0px;"> <br>

 

7)Score: <input name="sum1" id="hole7A" value="" onchange="calc(this.value,'hole7B','hole7result')" />

Par: <input name="sum2" readonly value="5" id="hole7B" onchange="calc(this.value,'hole7A','hole7result')" />

Par Score: <input name="sum7" value="" id="hole7result" readonly style="border:0px;"> <br>

 

8)Score: <input name="sum1" id="hole8A" value="" onchange="calc(this.value,'hole8B','hole8result')" />

Par: <input name="sum2" readonly value="5" id="hole8B" onchange="calc(this.value,'hole8A','hole8result')" />

Par Score: <input name="sum8" value="" id="hole8result" readonly style="border:0px;"> <br>

 

9)Score: <input name="sum1" id="hole9A" value="" onchange="calc(this.value,'hole9B','hole9result')" />

Par: <input name="sum2" readonly value="5" id="hole9B" onchange="calc(this.value,'hole9A','hole9result')" />

Par Score: <input name="sum9" value="" id="hole9result" readonly style="border:0px;"> <br>

 

Total par score: <input name="totalparscore" Id="totalparscore" />

 

<input type="submit" name="submit"/>

 

<?php $hole1 = $_POST['sum'];?>

<?php $hole2 = $_POST['sum2T'];?>

<?php $hole3 = $_POST['sum3'];?>

<?php $hole4 = $_POST['sum4'];?>

<?php $hole5 = $_POST['sum5'];?>

<?php $hole6 = $_POST['sum6'];?>

<?php $hole7 = $_POST['sum7'];?>

<?php $hole8 = $_POST['sum8'];?>

<?php $hole9 = $_POST['sum9'];?>

 

</form>

</body> </html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.