<html> <head> <script type="text/javascript" src="includes/controls/controls.js"></script> <script type="javascript/text"> function headFunction() { alert('Hello World!'); } </script> </head> <body bgcolor="#FFFFFF" onload="load_function();"> </body></html>
function load_function() { headFunction();}
<input type="button" id="buttonAccept"/>
function buttonAccept_onClick() { ... }
document.getElementById('buttonAccept').onclick = function() { buttonAccept_onClick() }
<html> <head> <script type="text/javascript" src="includes/controls/controls.js"></script> <script type="text/javascript"> function buttonAccept_onClick() { document.getElementById("frmMain").submit; } function buttonClear_onClick() { document.getElementById("txtName").value = "Enter your name" } function txtName_onBlur() { if (this.value == "") this.value = "Enter your name"; } function txtName_onFocus() { if (this.value == "Enter your name") this.value=""; } </script> </head> <body bgcolor="#FFFFFF" onload="init_events();"> <form id="frmMain" name="frmMain method="post" action="register.php"> <input type="text" id="txtName" name="txtName" value="Enter your name" /> <input type="button" id="buttonAccept" name="buttonAccept" value="Accept" /> <input type="button" id="buttonClear" name="buttonClear" value="Clear" /> </form> </body></html>
function getallids() { var allTags = document.body.getElementsByTagName('*'); var ids = []; for (var tg = 0; tg< allTags.length; tg++) { var tag = allTags[tg]; if (tag.id) { ids.push(tag.id); } } return ids;}function isFunction(funcname){ var isDefined = eval('(typeof '+funcname+'==\'function\');'); if (isDefined) { return true; } else { return false; }}function init_events() { var myEvents = new Array("click","blur","focus"); var allIds = getallids(); var myfunc = null; var curid = ''; var curevent = ''; for (var x in allIds) { for (var i in myEvents) { curid = allIds[x]; curevent = myEvents[i]; myfunc = curid+'_on'+curevent; if(isFunction(myfunc)) { document.getElementById(curid).addEventListener(curevent,function() { myfunc = eval(curid+'_on'+curevent); myfunc(); }, false); } } }}
function init_events() { var myEvents = new Array("Click","Blur","Focus"); var allIds = getallids(); var myfunc = null; var curid = ''; var curevent = ''; for (var x in allIds) { for (var i in myEvents) { curid = allIds[x]; curevent = myEvents[i]; myfunc = curid+'_on'+curevent; if(isFunction(myfunc)) { if (document.getElementById(curid).addEventListener){ document.getElementById(curid).addEventListener(curevent.toLowerCase(),function(e) { eType = e.type; switch (eType) { case 'click': eType = 'Click'; break; case 'focus': eType = 'Focus'; break; case 'blur': eType = 'Blur'; break; } myfunc = this.id + '_on' + eType; if(isFunction(myfunc)) { myfunc = eval(this.id + '_on' + eType); myfunc(); } }, false); } else if (document.getElementById(curid).attachEvent){ var r = document.getElementById(curid).attachEvent("on"+curevent.toLowerCase(), function(e) { myfunc = eval(curid+'_on'+curevent); myfunc(); }); } } } }}
.textbox { color: #333333; background-color: #ffffff; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; z-index: -3; font-family: tahoma,verdana,arial; font-size: 11px; padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px;}.textbox-disabled { color: #AAAAAA; background-color: #ffffff; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; z-index: -3; font-family: tahoma,verdana,arial; font-size: 11px; padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px;}.button { color: #333333; background-color: #AAAAAA; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; z-index: -3; font-family: tahoma,verdana,arial; font-size: 11px; padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px;}.button-disabled { color: #666666; background-color: #DDDDDD; background-image: none; background-repeat: repeat; background-attachment: scroll; background-position: 0% 0%; z-index: -3; font-family: tahoma,verdana,arial; font-size: 11px; padding-top: 2px; padding-right: 2px; padding-bottom: 2px; padding-left: 2px;}
function getInputIds() { var arrInputTags = document.body.getElementsByTagName("input"); var arrReturnIds = []; for (var iTag = 0; iTag < arrInputTags.length; iTag++) { var tagInput = arrInputTags[iTag]; if (tagInput.id) { arrReturnIds.push(tagInput.id); } } return arrReturnIds;}function isFunction(funcname){ var bDefined = eval( '(typeof ' + funcname + '==\'function\');' ); if (bDefined) { return true; } else { return false; }}function initEventHandler() { var arrEvents = new Array("click", "blur", "focus"); var arrInputIds = getInputIds(); var funcEventHandler = null; var strCurId = ''; var strCurEvent = ''; for (var x in arrInputIds) { for (var i in arrEvents) { strCurId = arrInputIds[x]; strCurEvent = arrEvents[i]; if (document.getElementById(strCurId).addEventListener){ document.getElementById(strCurId).addEventListener(strCurEvent, function(e) { evType = e.type; switch (evType) { case 'click': evType = 'Click'; break; case 'focus': evType = 'Focus'; break; case 'blur': evType = 'Blur'; break; } funcEventHandler = this.id + '_on' + evType; if ( isFunction(funcEventHandler) ) { funcEventHandler = eval(this.id + '_on' + evType); funcEventHandler(); } }, false); } else if ( document.getElementById(strCurId).attachEvent ) { var r = document.getElementById(strCurId).attachEvent("on" + strCurEvent, function(e) { evType = e.type; switch (evType) { case 'click': evType = 'Click'; break; case 'focus': evType = 'Focus'; break; case 'blur': evType = 'Blur'; break; } funcEventHandler = this.id + '_on' + evType; if ( isFunction(funcEventHandler) ) { funcEventHandler = eval(this.id + '_on' + evType); funcEventHandler(); } }); } } }}
<?php$arrControls = Array();class clsHTMLControls { public function startForm( $strName, $strMethod = "post", $strAction = NULL, $strStyle = NULL ) { global $arrControls; echo "<form id= \"".$strName."\" name=\"".$strName."\" "; echo "method=\"".( (in_array($strMethod, array("post", "get")))?$strMethod:"post" ). "\" "; echo "action=\"".$strAction."\" "; if ($strStyle) { echo "style=\"".$strStyle."\" "; } echo "> \n"; $arrControls[] = $strName; } public function addTextBox( $strName, $strDefaultValue = NULL, $strSize = NULL, $strMaxLangth = NULL, $bReadOnly = False, $bDisabled = False, $strStyle = NULL ) { global $arrControls; echo "<input type=\"text\" "; echo "id= \"".$strName."\" name=\"".$strName."\" "; echo "value=\"".$strDefaultValue."\" "; if ($strSize) { echo "size=\".".$strSize.".\" "; } if ($strMaxLangth) { echo "maxlength=\"".$strMaxLangth."\" "; } if ($bReadOnly) { echo "readonly='readonly' "; } if ($bDisabled) { echo "disabled=\"".strval($bDisabled)."\" "; } echo "class=\"textbox".( ($bDisabled)?"-disabled":"" )."\" "; if ($strStyle) { echo "style=\"".$strStyle."\" "; } echo "/> \n"; $arrControls[] = $strName; } public function addButton ( $strName, $strValue = NULL, $bDisabled = False, $strStyle = NULL ) { global $arrControls; echo "<input type=\"button\" "; echo "id= \"".$strName."\" name=\"".$strName."\" "; echo "value=\"".( ($strValue)?$strValue:"Command Button" )."\" "; if ($bDisabled) { echo "disabled=\"".strval($bDisabled)."\" "; } echo "class=\"button".( ($bDisabled)?"-disabled":"" )."\" "; if ($strStyle) { echo "style=\"".$strStyle."\" "; } echo "/> \n"; $arrControls[] = $strName; } public function initControls() { global $arrControls; echo "<script type=\"type/javascript\" > \n"; foreach ($arrControls as $objControl) { echo "var ".$objControl." = document.getElementById(\"".$objControl."\"); \n"; } echo "</script> \n"; } public function endForm() { echo "</form> \n"; } }?>
<?php require_once("includes/controls/controls.php"); ?><html> <head> <link href="includes/controls/controls.css" rel="stylesheet" type="text/css" media="all" /> <script type="text/javascript" src="includes/controls/controls.js"></script> <script type="text/javascript"> <!-- // ------------- cmdAccept events ------------- // function cmdAccept_onClick() { if ( txtName.value == "Enter your name...") { alert("Please enter your name!"); } else { frmMain.submit(); } } // ------------- cmdClear events ------------- // function cmdClear_onClick() { txtName.style.fontStyle = "italic"; txtName.style.color = "#999999"; txtName.value = "Enter your name..."; } // ------------- txtName events -------------- // function txtName_onBlur() { if (txtName.value == "") { txtName.style.fontStyle = "italic"; txtName.style.color = "#999999"; txtName.value = "Enter your name..."; } } function txtName_onFocus() { if (txtName.value == "Enter your name...") { txtName.style.fontStyle = "normal"; txtName.style.color = "#333333"; txtName.value = ""; } } // --> </script> </head> <body bgcolor="#FFFFFF" onload="initEventHandler();"> <?php clsHTMLControls::startForm("frmMain"); ?> <?php clsHTMLControls::addTextBox( "txtName", "Enter your name...", NULL, NULL, NULL, NULL, "font-style: italic; color: #999999;" ); ?> <?php clsHTMLControls::addButton( "cmdAccept", "Accept" ); ?> <?php clsHTMLControls::addButton( "cmdClear", "Clear" ); ?> <?php clsHTMLControls::endForm(); ?> <?php clsHTMLControls::initControls(); ?> </body></html>