Bruno Grange
Bruno Grange
"Imagination is more important than knowledge." (Einstein)

Content
Social
| JavaScript tips - String prototypes and key checks |
|
|
| Written by Bruno Grange |
| Wednesday, 03 September 2008 02:21 |
|
Here goes some usefull widgets... //removes all spaces from a string String.prototype.stripSpaces=function(){return this.replace(/\s/g,"");} //e.g. "Bruno is very poor".stripSpaces() returns "Brunoisverypoor" //replaces all occurrences of a String.prototype.replaceAll=function(s1,s2){return this.replace(new RegExp(s1,"g"), s2);} //e.g. "Bruno is poor, poor and poor".replaceAll("poor", "rich") returns "Bruno is rich, rich and rich" //verifies the key pressed by the user function KeyCheck(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; switch(KeyID) { case 16: document.Form1.KeyName.value = "Shift"; break; case 17: document.Form1.KeyName.value = "Ctrl"; break; case 18: document.Form1.KeyName.value = "Alt"; break; case 19: document.Form1.KeyName.value = "Pause"; break; case 37: document.Form1.KeyName.value = "Arrow Left"; break; case 38: document.Form1.KeyName.value = "Arrow Up"; break; case 39: document.Form1.KeyName.value = "Arrow Right"; break; case 40: document.Form1.KeyName.value = "Arrow Down"; break; } } Related Articles: |

