var TimeOfLastClick =0; // init at page load function onEndCrop( coords, dimensions ) { $( 'x1' ).value = coords.x1; $( 'y1' ).value = coords.y1; $( 'x2' ).value = coords.x2; $( 'y2' ).value = coords.y2; $( 'width' ).value = dimensions.width; $( 'height' ).value = dimensions.height; // get time of this click in milseconds var thisClick=new Date(); var thisClickMs = thisClick.getTime(); // if this click happened within 300ms of last one it's // a double click so submit a form named 'cropform' if ((thisClickMs - TimeOfLastClick)< 300 ) self.document.forms['cropform'].submit() // not double click so update global var //TimeOfLastClick with this click's timestamp TimeOfLastClick = thisClickMs; }