<input type="button" onclick="executes second" />
$('input').click(function() { //this first }}
p.s. onclick="executes second" - cannot be removed (its __doPostBack)
<input type="button" onclick="executes second" />
$('input').click(function() { //this first }}
p.s. onclick="executes second" - cannot be removed (its __doPostBack)
If you use jQuery the is no need to put onclick into the HTML:
$('input').click(function() {
//this first
something();
// this last
playSound();
});
Edit:
Just Remove the onclick attribute with jQuery:
$('input').removeAttr("onclick");
you could put it inside document ready or just attach it to your call
$('input').removeAttr("onclick").click(function() {...});
Couldn't you just do something like:
< input type="button" onclick="do_something();" />
function do_something() {
// this first
// then second?
}}
My guess is the inline onclick handler cannot be removed as it has been output by ASP.NET. To solve this problem you need to override ASP.NET's doPostBack method to inject your function before the postback takes place. Try including the following function in your page somewhere and then use it to add your event handler:
Update: Just re-read and realised this answer slightly misses the mark - it basically allows you to fire events prior to postback, but not necessarily attached to the button's onclick handler.
var addToPostBack = function(func) {
var old__doPostBack = __doPostBack;
if (typeof __doPostBack != 'function') {
__doPostBack = func;
} else {
__doPostBack = function() {
func();
old__doPostBack.apply(this, arguments);
}
}
};
...
<input type="button" id="btn" onclick="..." />
...
addToPostBack(function() { alert("You're posting back!"); });
try ...
$(document).ready(function(){
$("input").removeAttr("onclick");
$("input").click(function(){
// do first
my_first_function();
// do second
my_second_function();
return false;
});
});