Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

separate preventDefault() from function

Tags:

jquery

Instead of something like this

$('#submitbutton').click(function(e) {
    e.preventDefault(); //to avoid the submit button to reload the page and go page to page one.
/* computing dimensions */
});

I'd like to put my function somewhere else, like this :

$('#submitbutton').click(computeUserDimensions);

function computeUserDimensions(){
/* computing dimensions */
}

But then I don't where to put the preventDefault to provide the click (which is on a submit button) to go to another page.

Can you help me figure this out?

Thanks

like image 918
Louis Avatar asked Feb 17 '23 22:02

Louis


1 Answers

Add parameter event to your function and it will be passed by jQuery implicitly.

$('#submitbutton').click(computeUserDimensions);

function computeUserDimensions(event){
    /* computing dimensions */
    event.preventDefault();
}
like image 172
Adil Avatar answered Mar 07 '23 04:03

Adil