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

shawn_milochik at godivachoc.com shawn_milochik at godivachoc.com
Fri Jul 2 12:40:37 CDT 2004





Yeah, I did get it to do what I wanted.  Thanks again for spending the time
on it.
I guess I had a hard time getting this to work because I couldn't figure
out
how to work a regex into the function...  ;o)

Shawn




                                                                           
             flavio at economisa.                                             
             com.br                                                        
             Sent by:                                                   To 
             javascript-bounce         javascript at LaTech.edu               
             s at LaTech.edu                                               cc 
                                                                           
                                                                   Subject 
             07/02/2004 02:21          Re: [Javascript] attach actions to  
             PM                        all objects in a form?              
                                                                           
                                                                           
             Please respond to                                             
             javascript at LaTech                                             
                   .edu                                                    
                                                                           
                                                                           




Shawn,

  By your reply, I didnt understood if you made it or not, but I think
that now I did what you wanted:

===========//===========
      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;
            var LittoSubmitses = new Array();
            var a = 0;

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

               //if it is a submit button,
               //set it to be disabled onclick
               if (objEl.type == 'submit'){
                  LittoSubmitses[a++] = objEl;
                  objEl.onclick =
function(){for(jj=0;LittoSubmitses[jj];jj++) LittoSubmitses[jj].disabled =
true}
               }

            }


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

      }

      setEvents();

===========//===========

Changes:
  LittoSubmitses is an array that contais all submits from the form;
  a is only a count to iterate over LittoSubmitses;

Ps.: I love my variable names... u.u

---
Flavio Gomes
flavio at economisa.com.br



shawn_milochik at godivachoc.com wrote:

>
>
>Thanks very much.  Actually, I ended up having the function loop through
>the
>form and disable any object of type "submit".  That's what I wanted to do
>in the
>first place, but I thought I'd do it incrementally (just one button, at
>first,) because
>I had never used this kind of Javascript functionality before (
>objEl.onclick = ).
>
>Shawn
>
>
>
>
>

>             flavio at economisa.

>             com.br

>             Sent by:                                                   To

>             javascript-bounce         javascript at LaTech.edu

>             s at LaTech.edu                                               cc

>

>                                                                   Subject

>             07/02/2004 01:16          Re: [Javascript] attach actions to

>             PM                        all objects in a form?

>

>

>             Please respond to

>             javascript at LaTech

>                   .edu

>

>

>
>
>
>
>
>Shawn,
>  I know why.  ^^
>
>The onclick of the submit is receiving this:
>    function(){objEl.disabled = true;}
>
>  And when the event (onclick) occurs /objEl/ points to the last submit
>in the form, and that's the one that is going to be disabled, I changed
>to _this_:
>    function(){this.disabled = true;}
>
>And it worked fine here.
>
>Ps.: I found no reason to comment these lines..
>        //  var objEl = null;
>        //  var x = 0;
>
>Hope to Help,
>
>---
>Flavio Gomes
>flavio at economisa.com.br
>
>
>
>Troy III Ajnej wrote:
>
>
>
>>Try this:
>>-------------------------------------------------------------
>> var objForm = document.forms['thisForm'];
>>        //  var objEl = null;
>>        //  var x = 0;
>>------------------------------------------------------------
>>regards Bekim
>>
>>
>>
>>>From: shawn_milochik at godivachoc.com
>>>Reply-To: "[JavaScript List]" <javascript at LaTech.edu>
>>>To: javascript at LaTech.edu
>>>Subject: Re: [Javascript] attach actions to all objects in a form?
>>>Date: Fri, 2 Jul 2004 08:16:21 -0400
>>>
>>>
>>>
>>>
>>>
>>>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.

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




More information about the Javascript mailing list