Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Thursday, July 11, 2013

How to make a text box take only numeric input or any specific input as per user's requirement using JavaScript

In order to insert only numeric value from textbox this JavaScript code could be applied.
Same code can be modified to restrict the users to enter different keyboard inputs as per requirement.
This can be done by changing the ASCII value mentioned in the JavaScript file.


JAVASCRIPT CODE:

write this function under the JavaScript code.

 function isNumber(event)
   {
            var KeyBoardCode = (event.which) ? event.which : event.keyCode;
            if (KeyBoardCode > 31 && (KeyBoardCode < 48 || KeyBoardCode > 57))
            {
                return false;
            }
            return true;
    }


HTML CODE:

use this code in the textbox field to perform the required operation.

onkeypress="return isNumber(event)"

One can make the text box readonly and nothing can be pasted into that by adding the following script in textbox:

onKeyPress = "javascript: return false;" onPaste = "javascript: return false;"

Sunday, December 16, 2012

Add a property to gridview and enable required field validator on checkbox checked event.


Add Property to a gridview to use with Javascript.

 protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      #region Add-Parameter-onJavaScript-Functions
           if (e.Row.RowType == DataControlRowType.DataRow)
          {
            CheckBox chk = new CheckBox();
            chk = e.Row.FindControl("chkIsEdit") as CheckBox;
            chk.Attributes.Add("onChange", "EnableFields(" + e.Row.RowIndex.ToString() + ")");
          }
      #endregion
    }

------------------------------------------------------
Javascript Code 
------------------------------------------------------ 

Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Thursday, July 11, 2013

How to make a text box take only numeric input or any specific input as per user's requirement using JavaScript

In order to insert only numeric value from textbox this JavaScript code could be applied.
Same code can be modified to restrict the users to enter different keyboard inputs as per requirement.
This can be done by changing the ASCII value mentioned in the JavaScript file.


JAVASCRIPT CODE:

write this function under the JavaScript code.

 function isNumber(event)
   {
            var KeyBoardCode = (event.which) ? event.which : event.keyCode;
            if (KeyBoardCode > 31 && (KeyBoardCode < 48 || KeyBoardCode > 57))
            {
                return false;
            }
            return true;
    }


HTML CODE:

use this code in the textbox field to perform the required operation.

onkeypress="return isNumber(event)"

One can make the text box readonly and nothing can be pasted into that by adding the following script in textbox:

onKeyPress = "javascript: return false;" onPaste = "javascript: return false;"

Sunday, December 16, 2012

Add a property to gridview and enable required field validator on checkbox checked event.


Add Property to a gridview to use with Javascript.

 protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      #region Add-Parameter-onJavaScript-Functions
           if (e.Row.RowType == DataControlRowType.DataRow)
          {
            CheckBox chk = new CheckBox();
            chk = e.Row.FindControl("chkIsEdit") as CheckBox;
            chk.Attributes.Add("onChange", "EnableFields(" + e.Row.RowIndex.ToString() + ")");
          }
      #endregion
    }

------------------------------------------------------
Javascript Code 
------------------------------------------------------