Thursday, 8 August 2013

Trigger onchange event by default

Trigger onchange event by default

I have this script trimming leading and trailing spaces on input fields
function
trim(el){el.value=el.value.replace(/(^\s*)|(\s*$)/gi,"").replace(/[
]{2,}/gi," ").replace(/\n +/,"\n");return}
<input onchange="return trim(this)" type="text" value="">
and I have to add onchange="return trim(this)" in every instance of <input
type="text" value=""> to trigger it. Is it possible to make this script
triggered by default without having to add onchange="return trim(this)"
everywhere? Maybe with some an additional script that tell all input
fields to trigger it by default? I also run jquery on this site if that
helps.

No comments:

Post a Comment