WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

IE5 Specific DHTML Functions

Summary: This code adds and removes rows dynamically in IE 5. Table names, row names and form elements names have very specific formats.
 
Keywords: ADD
DHTML
DYNAMIC
FORM
IE5
Applicable Software: JavaScript
 
Body:

Yeah, this probably isn't very helpful for anyone but me. It's actually really powerful and allows you to dynamically add rows to a table and remove them.

E-mail me and I might get around to posting sample code for how to use it.

function swapVisibility(objectVisSwap, testString, testValue)
{
	objectVisSwap.style.display = ((testString == testValue) ? '' : 'none');
}

function deleteFormSection(sourceKeyName, deleteButton, formObj, altFieldToStore)
{
	var strImgBtnName = deleteButton.name;
		if(strImgBtnName.indexOf('imgDelete' + sourceKeyName + '_') == -1)
		{
			return false;
		}
	
	var vntSectionID;
	var intSectionID = 0;
		vntSectionID = strImgBtnName.substring(('imgDelete' + sourceKeyName + '_').length);
		intSectionID = parseInt(vntSectionID);
		vntSectionID = ',' + vntSectionID + ',';
		
		if(typeof(altFieldToStore) != 'undefined')
		{
			if(altFieldToStore.indexOf('_') > -1)
			{
				if(typeof(formObj[sourceKeyName.toLowerCase() + '_deletes']) != 'undefined' && typeof(formObj[altFieldToStore + intSectionID]) != 'undefined')
				{
					formObj[sourceKeyName.toLowerCase() + '_deletes'].value += intSectionID + '=' + formObj[altFieldToStore + intSectionID].value + ';';
				}
			}
		}
		
	var objTable = eval('tbl' + sourceKeyName);
	var objRow;
	var strAlpha = 'ZYXWVUTSRQPONMLKJIHGFEDCBA';
	var intAlphaLoc = 0;
	var intCNT = 0;
	
		for(intAlphaLoc = 0; intAlphaLoc < strAlpha.length; intAlphaLoc++)
		{
			objRow = objTable.rows['row' + sourceKeyName + intSectionID + strAlpha.charAt(intAlphaLoc).toLowerCase()];
			if(typeof(objRow) == 'object')
			{
				intCNT = 0;
				while(intCNT < objTable.rows.length && intCNT > -1)
				{
					if(objTable.rows[intCNT].id == objRow.id)
					{
						objTable.deleteRow(intCNT);
						intCNT = -100;
					}
					else
					{
						intCNT++
					}
				}
			}
		}
		
		if(rowItemCount(objTable, sourceKeyName) == -1)
		{
			swapVisibility(objTable.rows[0], objTable.rows[0].id, 'row' + sourceKeyName + 'DefaultNone')
		}
		
		buildFormSectionList(sourceKeyName, formObj);
		
		return true;
		
		
}

function addFormSection(sourceKeyName, formObj)
{
	var objTable = eval('tbl' + sourceKeyName);
	var objDefaultRow;
	var objRow;
	var iRowCount = rowItemCount(objTable, sourceKeyName);
	var strAlpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var intAlphaLoc = 0;
		
		if(iRowCount == -1)
		{
			if(objTable.rows[0].id == 'row' + sourceKeyName + 'DefaultNone')
			{
				objTable.rows[0].style.display = 'none';
			}
		}
		iRowCount ++;
		
		objDefaultRow = objTable.rows['row' + sourceKeyName + 'Default' + strAlpha.charAt(intAlphaLoc)];
		while(typeof(objDefaultRow) == 'object')
		{
			objRow = objDefaultRow.cloneNode(true);
			objRow = objTable.rows[objTable.rows.length - 1].insertAdjacentElement("afterEnd", objRow);
			objRow.id = 'row' + sourceKeyName + iRowCount + strAlpha.charAt(intAlphaLoc).toLowerCase();
			objRow.style.display = '';

			if(intAlphaLoc == 0 && iRowCount > 0)
			{
				if(objRow.hasChildNodes())
				{
					for(var intCNT = 0; intCNT < objRow.children.length; intCNT++)
					{
						objRow.children[intCNT].style.borderTop = 1;
						objRow.children[intCNT].style.borderTopColor = '#000000';
						objRow.children[intCNT].style.borderTopStyle = 'inset';
					}
				}
			}

			reIdentifyChildren(objRow, iRowCount);
			
			intAlphaLoc++;
			objDefaultRow = objTable.rows['row' + sourceKeyName + 'Default' + strAlpha.charAt(intAlphaLoc)];
		}
		
		buildFormSectionList(sourceKeyName, formObj);
		
		return iRowCount;
}

function reIdentifyChildren(sourceRow, rowItemCounter)
{
	var strTMP = '';
		
		strTMP = new String(sourceRow.id);
		if(strTMP.length > 0 && strTMP.charAt(strTMP.length - 1) == '_')
		{
			sourceRow.id += rowItemCounter;
		}
		
		strTMP = new String(sourceRow.name);
		if(strTMP.length > 0 && strTMP.charAt(strTMP.length - 1) == '_')
		{
			sourceRow.name += rowItemCounter;
		}
	
		if(sourceRow.hasChildNodes())
		{
			for(var x=0; x < sourceRow.children.length; x++)
			{
				reIdentifyChildren(sourceRow.children[x], rowItemCounter);
			}
		}
}

function buildFormSectionList(sourceKeyName, formObj)
{
	var strItemIDs = ',';
	var objTable = eval('tbl' + sourceKeyName);
	var objRows = objTable.rows;
	var iRowCount = objRows.length;
	var strID = new String('');
	
		for(var intCNT=0; intCNT < iRowCount; intCNT++)
		{
			strID = objRows[intCNT].id;
			if(strID.indexOf('Default') == -1)
			{
				strID = strID.substring(('row' + sourceKeyName).length, (('row' + sourceKeyName).length + strID.length -('row' + sourceKeyName).length + 1));
				
				if(strID.charAt(strID.length - 1) == "a")
				{
					strItemIDs += strID.substring(0, strID.length - 1) + ","
				}
			}
		}
		
		formObj[sourceKeyName.toLowerCase() + '_list'].value = strItemIDs;
}

function rowItemCount(sourceTable, sourceKeyName)
{
	var iItemCount = -1;
	var objRows = sourceTable.rows;
	var iRowCount = objRows.length;
	var strID = new String('');
	
		for(var intCNT=0; intCNT < iRowCount; intCNT++)
		{
			strID = objRows[intCNT].id;
			if(strID.indexOf('Default') == -1)
			{
				strID = strID.substring(('row' + sourceKeyName).length, (('row' + sourceKeyName).length + strID.length -('row' + sourceKeyName).length + 1));
				if(iItemCount < parseInt(strID))
				{
					iItemCount = parseInt(strID);
				}
			}
		}
		
		return iItemCount;
}

function removeBlankOption(selectBox)
{
	var intSelectedIndex = selectBox.selectedIndex;
	
		for(var intListIndex = 0; intListIndex < selectBox.options.length; intListIndex++)
		{
			if(selectBox.options[intListIndex].value.length == 0)
			{
				break;
			}
		}
		
		if(intListIndex < selectBox.options.length)
		{
			if (intListIndex < selectBox.options.length - 1)
			{
				for (var intCNT = intListIndex; intCNT < selectBox.options.length - 1; intCNT++)
				{
					selectBox.options[intCNT].value = selectBox.options[intCNT + 1].value
					selectBox.options[intCNT].text = selectBox.options[intCNT + 1].text
				}
			}
			
			selectBox.options.length--
			
			if(intSelectedIndex > intListIndex)
			{
				selectBox.selectedIndex = intSelectedIndex - 1;
			}
		}
}

function getRowCountID(sourceObj)
{
	var strTMP = sourceObj.id;
		if(strTMP.length == 0)
		{
			strTMP = sourceObj.name;
		}

		if(strTMP.lastIndexOf('_') > 0)
		{
			strTMP = strTMP.substring(strTMP.lastIndexOf('_') + 1, strTMP.length);
		}
		else
		{
			strTMP = '';
		}

		return strTMP;
}

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 3/5/2002 12:15:18 PM

Rate this article: Average: 5
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.