I wanted to implement client javascript to re-calculate summary based on a few options(in drop-down lists) selected by the user .
I created an array of custom class objects. Class has InitialPrice and SelectedPrice properties as well as
this.Diff = function( ) {
return this.SelectedPrice-this.InitialPrice;
}
Each DropDownList calls onchange Event Handler, which updates SelectedPrice value and calls RecalculateTotal();
The RecalculateTotal() basically does the following:
var totalDiff=0.0;
for(var i=0; i<g_arrOpnClasses.length;i++)
{
var opnClass= g_arrOpnClasses[i];
totalDiff=totalDiff+opnClass.Diff();
}
and shows recalculated summary.
Because it was my first JS code with classes, I've read a few articles to solve problems, that I meet:
To access the HTML element the event took place on:
function count(evt) {
var evt = evt || event;
var myObject = evt.target || evt.srcElement;
Considered to use JSON
To populate initial values in array I considered to use JSON, but later found that it is not nesessary. Any way below are a few links that were informative for me:
posted @ Saturday, August 16, 2008 1:28 PM