开发者

JavaScript KeyUp in All Of My Form (For Example Enter Key)-> Show An Alert

开发者 https://www.devze.com 2023-01-08 09:06 出处:网络
I know how can we use onkeyup event of an element... but I want to have an alert in all of my form areas when a client presses the enter key (for example) (not on an unique element)

I know how can we use onkeyup event of an element...

but I want to have an alert in all of my form areas when a client presses the enter key (for example) (not on an unique element)

Is there a function that already exists in Javascript to do this? Should I create a function to do this? Or should I put alert code (with nested if statements开发者_StackOverflow) in Javascript area code without using a function?

That was my #1 question..

My #2 question is:

I know differences about key events in IE and Firefox and ... (keycode and charcode and ...) What is the best way for using key events for IE and Firefox for detecting upper situation that I explained?


Answer to you first question :

more about keystrokes : Detecting keystrokes

Example to disable enterkey on press

<script type="text/javascript"> 

function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
}    
document.onkeypress = stopRKey; 

</script>


2. Question:

With this script you can detect upper/lower case:

<script type="text/javascript">

    
    function isUpper(String)
    {
        if(String.charCodeAt(0) > 64 && String.charCodeAt(0) < 91)
            return true;
        else
            return false;
    }
    
    if(isUpper("A"))
        alert("upper case");
    else
        alert("lower case");

</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号