<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
    主站蜘蛛池模板: 久久久久国产精品免费免费不卡 | 免费一级毛片一级毛片aa| 大地资源在线资源免费观看 | 四虎最新永久免费视频| 国产精品高清免费网站| 亚洲国产成人久久精品大牛影视 | 国产啪精品视频网站免费尤物 | 国产一精品一aⅴ一免费| 永久黄色免费网站| 色www永久免费网站| 免费福利在线观看| 亚洲国产欧美国产综合一区 | 成年在线网站免费观看无广告| 久久精品无码精品免费专区| 国产精品高清免费网站| 香蕉国产在线观看免费| 最新亚洲人成无码网站| 综合偷自拍亚洲乱中文字幕 | 免费看美女让人桶尿口| 在线观看的免费网站| 69式互添免费视频| 57pao一国产成视频永久免费| 国产成人免费视频| 中文无码成人免费视频在线观看| 国产99精品一区二区三区免费| 特级aa**毛片免费观看| 曰批免费视频播放免费| 日韩成人精品日本亚洲| 国产精品亚洲精品日韩电影| 国产精品亚洲专区无码唯爱网| 亚洲暴爽av人人爽日日碰| 亚洲国产精品无码久久98| 国产亚洲高清在线精品不卡| 国产综合成人亚洲区| 无套内谢孕妇毛片免费看看 | 国产精品亚洲精品日韩已满| 国产亚洲av片在线观看18女人| 亚洲人成无码网站| 亚洲AV无码久久精品色欲| 亚洲av日韩av无码| 亚洲高清资源在线观看|