Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
<script type="text/javascript">
      $(document).ready(function(){
            $("button").click(function(){
                confirm("Want to see the animation");},
                function(){
                    $("button").animate({left:'200px'}).fadeToggle("slow");
               });
          });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
          <button>submit</button>
    </div>
    </form>
</body>
</html>


The click event fires "when i only using alert or confirm". But when i started using another funtion the click event not firing. It just reloading the page again and again. pls give the solution...
Posted
Updated 19-Nov-12 20:25pm
v2

1 solution

You have done lots of mistake.
you cant call multiple method or function like this on onclick event.
click by default submit the form.its mean it reloads static page again. ie. in its prev state. you have to stop submission of form.

here i have modified your code its working well. as per your requirement .

JavaScript
<script type="text/javascript">
      $(document).ready(function(){
            $("button").click(function(e){						
                var flag = confirm("Want to see the animation");
				if(flag)
                 $(this).animate(
				 {
					width: "70%",
					opacity: 0.4,
					marginLeft: "0.6in",
					fontSize: "3em",
					borderWidth: "2px"
				}, 1500 ).fadeToggle("slow");
					e.preventDefault();
               });
          });
    </script>
 
Share this answer
 
v2
Comments
sathish k.kumar 20-Nov-12 3:14am    
thank u... very much... deepak....
deepak.m.shrma 20-Nov-12 4:35am    
Most welcome yaar :-)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900