01 August 2007
This post may be outdated due to it was written on 2007. The links may be broken. The code may be not working anymore. Leave comments if needed.
jQuery is pretty powerful. It's pretty easy to write a jquery js without change any html code.

I just wrote a small js to finish one task: disable the "submit" button when submit the form and let Ctrl+Enter submit the form like QQ message.

code is pretty simple:
$(document.forms).each( function(theform) {

// disabled the Submit and Reset when submit a form
// to avoid duplicate submit
$(theform).submit( function() {
$('input:submit').attr( { disabled : 'disabled' } );
$('input:reset').attr( { disabled : 'disabled' } );
} );

// Press Ctrl+Enter to submit the form. like QQ.
$(theform).keypress( function(evt) {
var x = evt.keyCode;
var q = evt.ctrlKey;

if (q && ( x == 13 || x == 10)) {
theform.submit();
}
} );

} );


If we are not using jQuery, we need change every <form in html files.(add onsubmit="javascript:SubmitOnce()" like).

jQuery operate on every form without changing any html files. that's amazing!

enjoy();


blog comments powered by Disqus