Thanks for your input gents.
I am building a company intranet, the intention is that we can have quick and efficient access to both the technical and pricing information from a single source (this info is currently held on 2 seperate systems), there are approximately 600 products each of which will have a number of configurable options.
The backend is an access database (which in turn calls data from our accounting software, where the product pricing information is held).
I am using Dreamweaver as my editor of choice and I utilise Adobe's Spry Framework for menu's, animation, data handling, etc. All product information comes into the page as a Spry XML Dataset.
In this particular instance I am only working on a test page so that a principle can be established, this is what I am trying to achieve;
Product_A is made up of 2 seperate components;
Component_1 has 5 options (call this ds1)
Component_2 has 5 options (call this ds2)
So Selling Price of Product_A = selection from ds1 + selection from ds2
The two datasets are presented in seperate tables, each with selectable rows and a seperate detail region that contains the price for the selected component. The price detail region updates when a different component is selected in the table.
The task here was to simply add together the 2 prices and have the total presented as a "Total Price"
So this is what was needed.
When page initially loads carry out the calculation based on the default selection in the two tables.
When a different selection is made in either of the tables (and the price in the detail region changes) carry out the calculation again.
This solution works:
MyScripts.js
Code:
function DelayedStartCalc(){
var t1=setTimeout("StartCalc()",3000);
var t2=setTimeout("StopCalc()",3500);
}
function DelayedStopCalc(){
var t2=setTimeout("StopCalc()",300);
}
function StartCalc(){
interval = setInterval("Calc()",1);
}
function StopCalc(){
clearInterval(interval);
alert ("Stopped"); //This is here for testing purposes only
}
function Calc(){
one = document.autoSumForm.firstBox.value;
two = document.autoSumForm.secondBox.value;
three = (one * 1) + (two * 1);
document.autoSumForm.thirdBox.value = three.toFixed(2);
}
On the <body>
Code:
<body onload="DelayedStartCalc()">
On the <tbody> of both tables
Code:
<tbody spry:repeat="ds1" spry:choose="choose" onmousedown="StartCalc()" onmouseup="DelayedStopCalc()">
The detail region
Code:
<form name="autoSumForm">
<div spry:detailregion="ds1"><input class="alignright" readonly="readonly" type=text name="firstBox" value="{Price}.00"></div>
<div spry:detailregion="ds2"><input class="alignright" readonly="readonly" type=text name="secondBox" value="{Price}.00" /></div>
<input class="alignright" readonly="readonly" type=text name="thirdBox" />
</form>
I would appreciate it if any of you .js guru's can suggest any improvement.