[Javascript] attach actions to all objects in a form?
Peter-Paul Koch
gassinaumasis at hotmail.com
Thu May 27 04:07:18 CDT 2004
>Is there a way to write an onclick function, or something
>similar, so that it applies to all objects on a form?
Yes. Register the event handler on the form. If the user clicks on a input
box, the click event bubbles up to the form and its click event fires. See
http://www.quirksmode.org/js/events_order.html for more explanation.
>What I mean is, without having to add any code to the
>objects themselves.
>
>Example (bad syntax):
>
><script type="text/javascript">
> function captureAllClicks(textbox){
[target].value = 'you just clicked this box';
// if called correctly, target is the box the user clicked on.
// see http://www.quirksmode.org/js/events_properties.html#target
> }
></script>
>
><form>
>
><input type="text" name="text1" id="text1" />
><input type="text" name="text2" id="text2" />
><input type="text" name="text3" id="text3" />
-------------------------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.quirksmode.org/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
------------------------------------------------------------------
_________________________________________________________________
MSN Search, for accurate results! http://search.msn.nl
More information about the Javascript
mailing list