kumbhani bhavesh kumbhani bhavesh - 10 months ago 43
Javascript Question

Call Javascript function using button OnClick event

I have one button like

<asp:Button ID="btnfirstnext" TabIndex="1" runat="server" Text="Next" class="action-button" OnClick="btnfirstnext_Click" />

and I have javascript like

$(function () {

//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches

$(".next1").click(function () {
if (animating) return true;
animating = true;

current_fs = $(this).parent();
next_fs = $(this).parent().next();

//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

//show the next fieldset

//hide the current fieldset with style
current_fs.animate({ opacity: 0 }, {
step: function (now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50) + "%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({ 'transform': 'scale(' + scale + ')' });
next_fs.css({ 'left': left, 'opacity': opacity });
duration: 800,
complete: function () {
animating = false;
//this comes from the custom easing plugin
easing: 'easeInOutBack'
// $('btnfirstnext').trigger('click');


I want to call this javascript when I click on button
please help me
I have try like
OnClientClick="javascript: return .next1;"
but it not work and I also try
class=".next1 action-button"
onclicentclick="return false;"
and this is work but I don't want to use this because of some other problem .


change your button id match with the click event id name next1 and remove OnClick="btnfirstnext_Click" from button

<asp:Button ID="next1" TabIndex="1" runat="server" Text="Next" class="action-button" />

and change your function parameter as bellow this will call this function

$("#next1").click(function () {