Javascript Functions

The following is a few javascript functions to modify the DOM object.

Get the value of a HTML element

function getVal(element)
{
	if (document.getElementById)
	{
		return document.getElementById(element).value;
	}
	else if (document.layers)
	{
		return document.layers[element].value;
	}
}

Set the value of a HTML element

function setVal(element,val)
{
	if (document.getElementById)
	{
		document.getElementById(element).value = val;
	}
	else if (document.layers)
	{
		document.layers[element].value = val;
	}
}

Set the InnerHTML of a HTML element

function setHTML(element, val)
{
	if (document.getElementById)
	{
		document.getElementById(element).innerHTML = val;
	}
	else if (document.layers)
	{
		document.layers[element].innerHTML = val;
	}
}

Get the InnerHTML of a HTML element

function getHTML(element)
{
	if (document.getElementById)
	{
		return document.getElementById(element).innerHTML;
	}
	else if (document.layers)
	{
		return document.layers[element].innerHTML;
	}
}

Set the display style of an element

  • Set val to “none” to hide
  • Set val to “block” or “inline” to display
function setDisplay (element, val)
{
	if (document.getElementById)
	{
		document.getElementById(element).style.display = val;
	}
	else if (document.layers)
	{
		document.layers[element].style.display = val;
	}
}

Delay script execution by x milliseconds

// This function pauses execution for x milliseconds
function pause(numberMillis) 
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) 
	{
		now = new Date();
		if (now.getTime() > exitTime)
		return;
	}
} 
 
/home/dodgydevil/wiki.zendfusion.com/data/pages/scripts/javascript.txt · Last modified: 2009/03/11 00:58 by bosbaba
[unknown button type]
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Zend Fusion