Java Script Syntax Help

  tbh72 10:30 14 Jan 2004

I have created a workbook "Excel" which I would like to replicate using forms, text boxes & javascript for the calculation. I have managed to find enough information to make the script Subtract one value "text box content" from another value "text box content" leaving the result in a third text box.

The problem with this is that I have to make this calculation 44 times using 88 individual text boxes.

Should I be looking at a javascript array, if, for and/or loop command to repeat the code for each calculation? and I am not familiar with javascript and would appreciate examples of the syntax for each command if possible.


  tbh72 12:42 14 Jan 2004

<script language=JavaScript>


function Calc()


var BStart1;

var BFinish1;

BStart1 = Number(Table.BStart1.value);

BFinish1 = Number(Table.BFinish1.value);

Table.BTotal1.value = BFinish1 - BStart1;

var BStart2;

var BFinish2;

BStart2 = Number(Table.BStart2.value);

BFinish2 = Number(Table.BFinish2.value);

Table.BTotal2.value = BFinish2 - BStart2;




Hopefully the above code will have presented itself in a readable manor. You can see by this code which cover's just 2 of the 44 calculations will make for a LARGE webpage. Is it possible to replace the numbers eg 1, 2, 3 etc for variables so the code simply repeats itself increasing the number by 1 eachtime. Scratching my head, but I cannot find out how to do it?!?!?

Thanks in advance

  Taran 21:39 14 Jan 2004

Is this for soem kind of quote system ?

Line breaks are everything when posting [and coding] JavaScript.

Depending on your requirements you would possibly be better served using a loop to progress through the calculations, but without a litle morer detail it is impossible to say which path to choose.

  tbh72 22:09 14 Jan 2004

I play in a tournament online. The tourney directors use pen & paper to calculate scores. I was attempting to create a system that would allow players to enter their own details. These could then be checked by the TD saving time. TD's could then access the results.

In the example above I have included the code for calculations for two players, this code would have to be repeated 44 time's for the system to work. This would make for massive amount's of code.

Using FP if you copy & paste a text box, the name remains the same with the exception of incremental numbers, could I apply the same principle to the code so the same sum is repeated adding 1 to the text box name each time?

Let me know what extra info you need?

  tbh72 02:00 15 Jan 2004

I have found another Forum which is specific to programming, if I can source the solution from there I will post it here & tick as resolved.

  tbh72 16:04 16 Jan 2004

Would it be helpful if I provided a link to a page that I am creating which includes my code thus far. I can't believe it's this difficult to manipulate Javascript to produce efficient repetitive code?!?

  tbh72 16:10 16 Jan 2004

<script language=JavaScript>


var BName = newArray(44);

var BStart = newArray(44);

var BFinish = newArray(44);

var BTotal = newArray(44);

var i;

function Calc()


for (i=1;i<=44;i++)


BStart(i) = Number(Table.BStart(i).value);

BFinish(i) = Number(Table.BFinish(i).value);

Table.BTotal(i).value = BFinish(i) - BStart(i);





The above script has been one suggestion received, this look's promising. However when I attempt to run the code it fails. But it does clearly show what I am trying to achieve, eg making each "text box" a variable which will loop until all calculations have been executed.

  Taran 16:44 16 Jan 2004

Out of curiosity, is your web server PHP or ASP active ?

  Taran 21:54 16 Jan 2004

Sorry, I've just realised that I posted that last reply in the wrong thread...

<< Hides head in shame.


  tbh72 21:55 16 Jan 2004

The server in question is unix/apache & php/mysql.

  tbh72 21:58 16 Jan 2004

LOL, I was wandering where you were going with it?!?!?

It might not be possible to do what I want with JS, but I really don't want to give up until I am certain it can't be done. It's just a matter of wading through the different functions & object's and seeing if they will work.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Best Black Friday Deals 2017

How modern book design was influenced by illustrated manuscripts

Best Black Friday Apple Deals 2017

Les meilleurs logiciels de montage vidéo gratuits (en 2017)