www.webdeveloper.com
Results 1 to 7 of 7

Thread: How to do that

  1. #1
    Join Date
    Mar 2006
    Posts
    8

    How to do that

    Hi friend

    I wanted to create a Text box in which you are able only enter alphabatics
    values if we entered any other value like 123, or text with numeric then it give us alert that enterd only in aplhabatics.

    Please help me to create this thing in JavaScript

    Thanks.

  2. #2
    Join Date
    Mar 2006
    Posts
    148
    ummm must involve
    onfocus
    for the form
    and onkeyup
    and keyCode
    I will see if I can give you an example in a bit

  3. #3
    Join Date
    Mar 2006
    Posts
    148
    <html>
    <head>
    <script type="text/javascript">
    function whichButton(event)
    {
    var x=event.keyCode
    if(x>4 && x<57)
    {
    alert('please enter letters only');
    document.a.b.value="";
    }
    }
    </script>
    </head>

    <body>

    <form name="a">
    <input type="text" name="b" onkeyup="whichButton(event)">
    </form>
    </body>
    </html>
    pretty basic but you get the idea

  4. #4
    Join Date
    Mar 2006
    Posts
    8
    It's not working domiereavron

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title>only alphabetic</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <script type="text/javascript">
    function checkData(e) {
    var key=(document.all)? event.keyCode : e.keyCode;
    if(key!=8) { // allow backspace
        if (key<65 || key>90) { // not alphabetic
            if (document.all) {
                window.event.returnValue=false;
                }
            else {
                if (e.cancelable ) {e.preventDefault();}
                }
            }
        }
    }
    
    // Register event
    window.onload=function() {
    if(document.getElementById('data')) {
        if(window.attachEvent) {
        	document.getElementById('data').attachEvent('onkeydown', checkData);
        	}
        else {
        	document.getElementById('data').addEventListener("keydown", checkData, false);
        	}
        }
    }
    </script>
    
    </head>
    <body>
    <form action="#" name="form1">
    <div>
    <input type="text" id="data">
    </div>
    </form>
    </body>
    </html>

  6. #6
    Join Date
    Mar 2006
    Posts
    148
    my bad I was typing that up right in there, it is just that it has to be larger then 47 , but other then that your good to go, if you want to enable
    things like the shift key you need to throw in a condition about the shift key

  7. #7
    Join Date
    Feb 2006
    Posts
    26
    Usman!
    use this small one
    <html>
    <head>
    <script type="text/javascript">
    function ChkValue()
    {
    var bx = "";
    bx = document.ax.bt.value;
    var i = 0;
    for(i=0; i<=9; i++)
    {
    if(bx.indexOf(i)!=-1)
    {
    alert("use alphbetic only");
    return false;
    break;
    }
    }

    }
    </script>
    </head>

    <body>

    <form name="ax">
    <input type="text" name="bt" onBlur="return ChkValue();">
    </form>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles