Thursday, August 09, 2007

BIG NEWS!

My wife is pregnant. I'll be a DADDY!
Wednesday, August 08, 2007

share slides

Wednesday, August 01, 2007

Powerful jQuery for SubmitOnce

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();