Web JavaScripts
Add commas to a number
For example:
function insert(form) {
var re = /(-?\d+)(\d{3})/
var num = form.entry.value
while (re.test(num)) {
num = num.replace(re,"$1,$2")
}
form.commaOutput.value = num
}Remove commas from a number
function remove(form) {
var re = /,/g
form.plainOutput.value = form.commaInput.value.replace(re,"")
}Masking Comments in a Report
function CThis(cx) {
// split on spaces
var cy;
if(cx.indexOf(" ")==0) { return cx; }
cy=cx.split(" ");
cx='';
key='aaaabbccddeeeefgfhhiiiijklllmnnnooopqrrrrssssstttttuv';
for(cz=0;cz<cy.length;cz++) {
var cl=cy[cz].length;
for(ca=0;ca<cl;ca++) {
cx+=key.substr(Math.random()*key.length,1);
}
cx+=' ';
}
return cx;
}Dynamically generated select lists
See example at:
PfDynamicLists.htm
var iArrayMax = 16
var aDropdown = new Array(iArrayMax)
//as the page loads - first thing to do is to load the dropdown array
var bOk = LoadArrays()
function sElement(sParentId,sValue,sDescription){
// elements that will be loaded into the array structure and persisted
// think of it as an object.
this.ParentId = sParentId
this.Id = sValue
this.Description = sDescription
}
function bCascadeDrop(oDDsource,oDDdest){
//function to enable cascading dropdowns
//called as the parent dropdown changes.
var iX
var sText
var iY= 0
var sOptionId
var sOptionDesc
var iStartPos
//find the value of the item currently selected
sText = oDDsource.options[oDDsource.selectedIndex].value
if (sText != '0')
{
//clear down the destination list box
oDDdest.options.length = 0
//loop through the elements that are in the array
// if they match the parent if then they should be displayed.
for (iX=0; iX<=iArrayMax; iX++)
{
if(sText == Array[iX].ParentId)
{
//grab the values out of the element
sOptionId = Array[iX].Id
sOptionDesc= Array[iX].Description
oDDdest.options[iY] = new Option (sOptionDesc,sOptionId)
iY = iY +1
}
}
}
}