...

View Full Version : A few more functions...



WillGibson
12-17-2003, 06:06 PM
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.




// 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,s tatus=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 = "";
}
}

Spookster
12-17-2003, 07:16 PM
You might want to put comments inside each one describing its purpose, what inputs it requires and what its output will be as well as what browsers it works in.

WillGibson
12-17-2003, 09:03 PM
That would help :)

Added some comments.

Will

chup
12-26-2003, 09:19 AM
thanks :)

brothercake
12-28-2003, 11:48 PM
Sorry man, but most of my comments are critisism:

Disabling the backspace key is not something I would condone. Manipulating keyboard returns as part of form validation is, imo, a highly dubious practise which creates confusion for users. And doing it in order to "control" history navigation is even worse - you simply shouldn't be trying to do that, and it only affects unaware IE-users anyway, compounding the perception of that browser as a security monster with no respect for user's preferences.

btw - does cancelBubble really have that effect in IE? That doesn't make any sense, because keyboard events don't bubble.

I also disagree with the use of modal dialogues, whether on the web or in local applications. I consider them the last resort of bad interface design, forcing the user into a fixed order of input purely for the convenience of the author.

WillGibson
12-29-2003, 03:21 PM
All my sites are Intraweb, I'm not using that as an excuse. What that does mean is, I know my users. To be honest, most of them are brick dumb. Any complication that I can avoid by limiting the actions and activities of my users I will do. They thank me and the support desk thanks me.

If I had suave users I could do things different. It would be less work for me and in general make my life easier. I would welcome it. The process of educating users is sloooow, at least with mine. I have not the time, energy or money to deal with it in a proper fashion.

By giving my users less freedom, I give them less ways to hurt themselves. Why? Because that means I and my developers spend less time cleaning up the mess of a "user error" and more time doing productive work. (I know user errors should not cause huge problems in well designed systems, but I did not design the old systems I have to interface with)

And yes onKeyDown, onKeyUp and onKeyPress do bubble in IE6.

btw criticism is the only way any of us get better. We must question ourselves and others. Please keep it up.

Thanks,
Will



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum