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

shawn_milochik at godivachoc.com shawn_milochik at godivachoc.com
Fri Jul 2 07:30:20 CDT 2004





Sorry, it looks like I have everything figured out.  I guess my browser was
caching the
JavaScript or something, but I finally got the behavior I expected.

Shawn




                                                                           
             Shawn                                                         
             Milochik/US/GODIV                                             
             A/CSC at CSC                                                  To 
             Sent by:                  javascript at LaTech.edu               
             javascript-bounce                                          cc 
             s at LaTech.edu                                                  
                                                                   Subject 
                                       Re: [Javascript] attach actions to  
             07/02/2004 08:16          all objects in a form?              
             AM                                                            
                                                                           
                                                                           
             Please respond to                                             
             javascript at LaTech                                             
                   .edu                                                    
                                                                           
                                                                           








Follow up:

I have it working, but now it is always disabling the same button,
no matter which was pressed.  Any ideas?

Thanks,
Shawn

---------------------------
code
---------------------------

    <script type="text/javascript">


      setEvents();



      function setEvents(){



         //check to see if the form has
         //loaded yet
         if (document.forms['thisForm']){

            var objForm = document.forms['thisForm'];
            var objEl = null;
            var x = 0;

            //for each element on the form
            for (x=0; x<objForm.elements.length; x++){
               objEl = objForm.elements[x];

               //if it is a submit button,
               //set it to be disabled onclick
               if (objEl.type == 'submit'){
                  objEl.onclick = function(){objEl.disabled = true;}
               }

            }


         //if the form didn't load yet, re-schedule
         //this function call
         }else{
            setTimeout('setEvents()', 5000);
         }

      }



---------------------------
end code
---------------------------






             Shawn
             Milochik/US/GODIV
             A/CSC at CSC                                                  To
             Sent by:                  javascript at LaTech.edu
             javascript-bounce                                          cc
             s at LaTech.edu
                                                                   Subject
                                       Re: [Javascript] attach actions to
             07/02/2004 08:02          all objects in a form?
             AM


             Please respond to
             javascript at LaTech
                   .edu










Hi everybody.  I just tried to implement something suggested by Chris in
response to one of my old questions, and I'm having a bit of a problem.

I keep getting the error "Not Implemented" when the script executes.
The line causing the error is :
                    if (objEl.type == 'submit'){

Thanks,
Shawn

--------------------------------
Here is the function:
--------------------------------


    <script type="text/javascript">

      function setEvents(){


         //check to see if the form has
         //loaded yet
         if (document.forms['thisForm'].elements){

            var objForm = document.forms['thisForm'];
            var objEl = null;
            var x = 0;

            //for each element on the form
            for (x=0; x<objForm.elements.length; x++){
               objEl = objForm.elements[x];

               //if it is a submit button,
               //set it to be disabled onclick
               if (objEl.type == 'submit'){
                  objEl.onclick = objEl.disabled = true;
               }

            }

         //if the form didn't load yet, re-schedule
         //this function call
         }else{
            setTimeout('setEvents()', 5000);
         }

      }

   </script>

--------------------------------
End of code.
--------------------------------





             christ at saeweb.com
             Sent by:
             javascript-bounce                                          To
             s at LaTech.edu              javascript at LaTech.edu
                                                                        cc

             05/26/2004 02:37                                      Subject
             PM                        Re: [Javascript] attach actions to
                                       all objects in a form?

             Please respond to
             javascript at LaTech
                   .edu






I've never personally used addEventListener, but would something like this
work?

======================

var objForm = document.forms["formName"]
var objEl = null
for(var x = 0; x < objForm.elements.length; x++){
    objEl = objForm.elements[x]
    objEl.onclick = captureAllClicks
    // which should also be able to be written as:
    // objEl.onclick = function(){
    //     Some code in here
    //}
}

function captureAllClicks(){
    // I'm confused on why you're passing in textbox in
    // your original code so I don't know how you would
    // write this function so that it works properly
}

======================


I really should test this code before sending, but...

:)

Chris Tifer


----- Original Message -----
From: "Roger Roelofs" <rer at datacompusa.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Wednesday, May 26, 2004 2:12 PM
Subject: Re: [Javascript] attach actions to all objects in a form?


> Shawn,
>
> On May 26, 2004, at 1:52 PM, Shawn Milo wrote:
>
> > Is there a way to write an onclick function, or something
> > similar, so that it applies to all objects on a form?

> > <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>

> Yes,
>
> ///  setup
> var el = document.getElementById("theContainer");
> if (el) {
> if( el.addEventListener ) {
> el.addEventListener("click", clickableTableRowClick, false);
> } else {
> if(el.attachEvent) {
> el.attachEvent("onclick", clickableTableRowClick);
> } else {
> el.onclick = clickableTableRowClick;
> }
> }
> }
>
> // callback routine
> function clickableTableRowClick(evt) {
> var targ, oldRow;
>      if (!evt) evt = window.event;
>      if (evt.target) targ = evt.target;
>      else if (evt.srcElement) targ = evt.srcElement;
> ...
> do what you want with the target element

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




**********************************************************************
This e-mail and any files transmitted with it may contain
confidential information and is intended solely for use by
the individual to whom it is addressed.  If you received
this e-mail in error, please notify the sender, do not
disclose its contents to others and delete it from your
system.

**********************************************************************

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list