<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 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      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 閱讀(385) 評論(0)  編輯  收藏 所屬分類: JQuery
    主站蜘蛛池模板: 久久亚洲精品中文字幕| 中文字幕亚洲综合久久男男| 亚洲网址在线观看| 久久青草免费91线频观看站街| 伊人久久亚洲综合| 最近免费字幕中文大全| 亚洲国产精品成人久久| 成人久久免费网站| 亚洲福利一区二区| 中文字幕无码不卡免费视频| 亚洲中文字幕一二三四区| 永久黄网站色视频免费观看| 青娱乐在线免费观看视频| 亚洲人AV永久一区二区三区久久| 久久毛片免费看一区二区三区| 亚洲自偷自偷偷色无码中文| 久久成人a毛片免费观看网站| 亚洲精品私拍国产福利在线| 国产精品视频免费| 亚洲精品女同中文字幕| 亚洲无码日韩精品第一页| 久久免费国产精品一区二区| 亚洲人成在线免费观看| 国产成人3p视频免费观看| 久久一区二区免费播放| 亚洲精品影院久久久久久| 国产精品公开免费视频| 好紧我太爽了视频免费国产| 亚洲av无码片区一区二区三区| 在线观看免费亚洲| a级成人毛片免费视频高清| 亚洲一卡二卡三卡| 亚洲性日韩精品一区二区三区| 美女内射无套日韩免费播放| 亚洲AV一区二区三区四区| 国产午夜亚洲精品理论片不卡| 国产91免费视频| 国产免费AV片在线观看播放| 亚洲欧洲日韩国产| 亚洲综合精品网站在线观看| 6080午夜一级毛片免费看6080夜福利 |