Click here to Skip to main content
13,296,374 members (53,655 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how to use javascipt function from .js file and i want to apply this function to textbox.

Ex:I have to do like this...

my textbox not allow numeric values.To do this I have make fuction.This function is in .js file.Now I have to use this function for textbox. I don't know javascript any one can help me..
Posted 22-Dec-12 23:08pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


In your HTML code, add this:
<script type="text/javascript" src="yourJavascriptFile.js"></script>

Now, your external JavaScript is loaded, and you can call your function.

Hope this helps.
Member 9511889 23-Dec-12 5:06am
after this step,how to apply validation of function to textbox.
ProgramFOX 23-Dec-12 8:21am
Then, you can call your JavaScript function in your external file in your HTML file:
<script type="text/javascript">
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

>> First of all load the js file like

<script language="javascript" type="text/javascript" src="jsfilelocation/filename.js" />

>> Remeber to return true / false based on the condition in your validation function.
For example, in your js file, let's say there is a method called Validate() that validates the textbox. SO the function should return true / false

function Validate()
   // Validation code.
   // If numeric return true else return false;

>> Now in your submit button write...
<asp:Button ID="btnSave" runat="server" CssClass="ActionButton" Text="Save" ValidationGroup="vgAddress"
               OnClick="btnSave_Click" OnClientClick="javascript:return Validate();" 
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try adding this function

function isAlphabet(elem){
    var alphaExp = /^[a-zA-Z]+$/;
        return true;
        alert("Can Not Contain Number");
        return false;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100