Tuesday, August 10, 2010

Call more then one JavaScript function on same event


Today I am working on how call more then one JavaScript function on same event. To achieve this I make some goggling and find solution, which I am sharing with you guys. My Basic requirement is when user enters value in text box the value must be numeric and if text box is not blank then it show save and cancel else hide save cancel button. So this can be achieved by two ways. So here I am representing both way.


ASP.NET 4.0, JQuery, JavaScript




Visual Studio 2005 and Later, my project definition in visual studio 2010.



Open visual studio 2010 project and Create new website

You can notice one thing there is Scripts file folder are included in project with Jquery virsion 1.4.1 and Default style sheet style.css in visual studio 2010 when we create new website project.
Open Default.aspx Source view. Add one Textbox Server control and two Button for Save and cancel..

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

    CodeFile="Default.aspx.cs" Inherits="_Default" ClientIDMode="Static" %>

No of item :

Above code snipped you notice one thing like ClientIDMode="Static” why I am put that will explain in next article

You can achieve this functionality without call two function on same event like this way call showSaveCancel() function inside intOnly() function like

function intOnly(i) {
 if (i.value.length > 0) 
i.value = i.value.replace(/[^\d]+/g, '');showSaveCancel(); 


Here I am trying to share how call more then one JavaScript function on same event.

Happy Coding

Thank you for Reading

Kirti M Darji