Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
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 well.so any one can help me..
Posted 22-Dec-12 22:08pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
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.
  Permalink  
Comments
Member 9511889 at 23-Dec-12 5:06am
   
after this step,how to apply validation of function to textbox.
ProgramFOX at 23-Dec-12 8:21am
   
Then, you can call your JavaScript function in your external file in your HTML file: <script type="text/javascript"> functionInExternalFile(); </script>
Rate this: bad
good
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();" 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try adding this function
 
function isAlphabet(elem){
    var alphaExp = /^[a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert("Can Not Contain Number");
        elem.focus();
        return false;
    }
}
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 412
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 235
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid