[Javascript] attach actions to all objects in a form?

Shawn Milo milo at linuxmail.org
Wed May 26 12:52:14 CDT 2004


Is there a way to write an onclick function, or something
similar, so that it applies to all objects on a form?

What I mean is, without having to add any code to the
objects themselves.

Example (bad syntax):

<script type="text/javascript">
   function captureAllClicks(textbox){
      //this happens on the
      //onclick event of any
      //text box on the form

      textbox.value = 'you just clicked this box';
   }
</script>

<form>

<input type="text" name="text1" id="text1" />
<input type="text" name="text2" id="text2" />
<input type="text" name="text3" id="text3" />

</form>


Thanks,
Shawn



More information about the Javascript mailing list