Another set of functions I have used to make my life easier.
By chance someone else will find use for them.
Once again I write for IE (4 to 6) as that is what I have to use.
PHP Code:
// used to cancel unwanted events, my most common use is
// <FORM onSubmit=fEventCancel() > as most time I don't let
// submits happen outside of code/script...WRG
function fEventCancel() {
event.returnValue=false;
}
// used to disable the backspace at the document level, like this:
// document.onkeydown = fKillBackspace;
function fKillBackspace() {
// Use onKeyDown="fOnKeyDo(8,'window.event.cancelBubble = true;')"
// on input fields that you wish the backspace key to work on...WRG
if (window.event && window.event.keyCode == 8) { // try to cancel the backspace
window.event.cancelBubble = true;
window.event.returnValue = false;
return false;
}
}
function fSetAsNextTab(element) {
// Use as the onBlur action...WRG
element.focus();
}
function fPopCenterWindow(strURL, strWindowName, intWinH, intWinW, boolIEModalD){
// Basic Centered Popup window...WRG
var intLeftPos = (screen.width) ? (screen.width-intWinW)/2 : 0
var intTopPos = (screen.height) ? (screen.height-intWinH)/2 : 0
if ((boolIEModalD) && (window.showModalDialog)) {
var newWindow = window.showModalDialog(strURL, window, 'dialogHeight:'+intWinH+'px;dialogWidth:'+intWinW+'px;center:yes;help:no;resizable:no;status:no');
} else {
var newWindow = window.open(strURL, strWindowName, 'height='+intWinH+',width='+intWinW+',top='+intTopPos+',left='+intLeftPos+',toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=yes')
}
}
function fOnKeyDo(intKey,strDo){
// Do action when key is pressed...WRG
var keyCode = event.keyCode
if (keyCode == intKey) {
eval(strDo);
}
}
// Used in a frame to return a form object from that frameset's opener document object
function fOpenerWindowForm(boolIEModalD,strForm){
if ((boolIEModalD) && (window.showModalDialog)) {
if ((parent.window.dialogArguments) && (eval("parent.window.dialogArguments."+strForm))) {
return parent.window.dialogArguments;
}else{
return parent.opener; // replace with top.opener if needed
}
}else{
return parent.opener; // replace with top.opener if needed
}
}
// Used in a frame to return that frameset's opener document object
function fOpenerWindow(boolIEModalD){
if ((boolIEModalD) && (window.showModalDialog)) {
if (parent.window.dialogArguments) {
return parent.window.dialogArguments;
}else{
return parent.opener;// replace with top.opener if needed
}
}else{
return parent.opener;// replace with top.opener if needed
}
}
// Hide an object
function fHideObj(Obj) {
if (Obj.style.display != "none") {
Obj.style.display = "none";
}
}
// Unhide an object
function fUnHideObj(Obj) {
if (Obj.style.display != "") {
Obj.style.display = "";
}
}