You must Sign In to post a response.

how to call javascript on button click

hi,

i had written the javascript for checking a textbox , value whihc entered is numbers alone, if it s char thenalrt msg

now how to callthe same on the button click event

function valNumeric()
{
if (event.keyCode >= 48 && event.keyCode <= 57) event.returnValue = true;
elseevent.returnValue=false;
}

how to call this script on button click , pls tel me


Comments

Author: Pradeep Kintali23 Sep 2008 Member Level: Gold   Points : 3

//Add the below code in

PageIntialisation

buttonName.Attributes.Add("onclick", "javascript: valNumeric();");

Or else

Author: K. B. Rao23 Sep 2008 Member Level: Silver   Points : 1

Hi,


Below is the sample code.



Author: Sam23 Sep 2008 Member Level: Bronze   Points : 4

hi,

There is a property available in ASP.NET button control called 'onclientclick'. you can use this property to call javascripts.

Example:
asp:button id="Button1"
usesubmitbehavior="true"
text="Open Web site"
onclientclick="Navigate()"
runat="server" onclick="Button1_Click" />

Author: D.Jeya kumar(JK)23 Sep 2008 Member Level: Gold   Points : 4

Hi,


You can call the java script from two places. directly from a button click of from server side page load or button click


by using the below client side button you can call



otherwise

Page.RegisterClientScriptBlock("test", "");

Regards
JK

Author: paresh23 Sep 2008 Member Level: Silver   Points : 4

hi

IF you are calling javascript function in codebehind than

btn_submit.Attributes.Add("onClick", "javascriptfunctionname();");

IF you are calling javascript function in aspx page(html)


Author: bill23 Sep 2008 Member Level: Gold   Points : 5

hi

the id of textbox on which you enter the value is TextBox1




you can call the javascript using onclientclick.


Author: Victoria23 Sep 2008 Member Level: Gold   Points : 2

in the Page_Load you have to add the attribute..

btn.Attribute.Add("onClick","javascript:valNumeric();");

Author: vamshi krishna23 Sep 2008 Member Level: Silver   Points : 4

Hi,
in design u write the following code


Write the following code on .cs file in page load event


Button1.Attributes.Add("OnClick","return Validate()");

Author: G.Hemadribabu23 Sep 2008 Member Level: Gold   Points : 3

hi friends

in my above javascript where can i include my textbox id , i am confused, please guide me , and i got that script in the net


thank you
hemadribabu

Author: Vivek Sharma23 Sep 2008 Member Level: Gold   Points : 4

Hi,

You can call java script function by calling it on pageload

//Write this Code on page load//

btnSave.Attributes.Add("onClick", "return validate();");

consider btnSave is the id of button and validate is a

function of java script we have made in aspx page.

Regards
Vivek Sharma

Author: Ravi Kiran Nedunuri24 Sep 2008 Member Level: Gold   Points : 4

in page load event write
btnSubmit.Attributes.Add("onclick", "return valNumeric();");


Or write in .aspx page as



the above are the two ways to call a javascript function

Regards

N.RaviKiran


Sign In to post your comments