<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    Few days back, my friend Parleen asked me how can we make a textbox which just accepts only numbers specially digits only. And, for his I come up with this solution of textbox which only accepts digits, and if you try to enter any alpha bates in it then it displays the error message with animation.

    View Demo

    HTML Code

    <input type="text"name="quantity"id="quantity"/><span id="errmsg"></span>

    As you can see above, I’ve given the name and id of textbox to “quantity” in this example.This is the textbox which only accepts numbers (digits only). You can see “span” after textbox which is used to display the error message with fading effect using jQuery.

    Javascript Code

    First of all, we need to use jQuery library as we’re using the jquery’s function to accept only digits.

    <script type="text/javascript"src="jquery.js"></script>

    Now le’ts write the code in JavaScript using jQuery to accept only digits in textbox and displaying error with animation.

    //when key is pressed in the textbox$("#quantity").keypress(function (e)

    {

      //if the letter is not digit then display error and don't type anything

      if( e.which!=8&& e.which!=0&&(e.which<48|| e.which>57))

      {

        //display error message

        $("#errmsg").html("Digits Only").show().fadeOut("slow");

        returnfalse;

      }

    });

    When the key is pressed, we’re using the key’s ASCII value to check which button is pressed. In first expression, delete, tab or backspace button is is checked and “8″ is the ASCII values of the Back-space. Digits are checked in the second expression. “48″ is the ASCII values of “0″ and “57″ is the ASCII values of “9″. The the ASCII values of the other digits lies between “48″ to “57″. And, if the key pressed values doesn’t lies withing these range, then we are displaying the error message with jQuery’s fading effect.

    And, the “return false” statement means that this functions returns false values which means not to type anything on the text box.

    Download Full Source Code

    posted on 2009-11-06 17:46 seal 閱讀(386) 評論(0)  編輯  收藏 所屬分類: JQuery
    主站蜘蛛池模板: 亚洲国产精品无码久久青草| 国产人在线成免费视频| 国产免费无遮挡精品视频| 亚洲avav天堂av在线网爱情| 青草草色A免费观看在线| 亚洲成av人片在线看片| 黄网站色在线视频免费观看| 日韩免费一区二区三区| 亚洲精品无码专区| 手机看片久久国产免费| 免费看一级一级人妻片 | 一个人看的在线免费视频| 亚洲精品美女久久久久99小说| 男女男精品网站免费观看| 久久久久亚洲精品无码网址| 99久久免费国产特黄| 成人毛片18岁女人毛片免费看| 精品亚洲456在线播放| 国产免费观看视频| 亚洲精品视频免费观看| 亚洲成色在线综合网站 | 亚洲精品免费视频| 亚洲国产亚洲片在线观看播放| 成人免费毛片内射美女APP| 国产成人人综合亚洲欧美丁香花| 亚洲精品国产高清嫩草影院| 国产一区二区免费| 久久精品国产精品亚洲人人 | 亚洲精品福利你懂| 四虎1515hm免费国产| a级毛片免费播放| 亚洲a∨无码男人的天堂| 免费一级毛片清高播放| 亚洲国产成人久久一区二区三区| 亚洲第一成人影院| 中文字幕在线免费| 亚洲AV天天做在线观看| 成年女人视频网站免费m| 中文字幕成人免费高清在线| 亚洲午夜久久久久久尤物| 又黄又大又爽免费视频|