Dynamically setting an event.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Dynamically setting an event.

    Greeting All:

    Time to pick the collective brain cell again. I have a web page that
    adds options to a select box on the fly. What I need to do is set the
    onDblClick event the same way. I need to call a function when the
    user double clicks on anything in the list box.

    ANy help would be greatly appreciated.

    THanks
    David
    973-292-8656


    I set the object initially as such:
    <select style="visibili ty: hidden; border:none;" multiple name="xxx"
    id="xxx" ></select>

    UPon the click of various other objects on the page, the option(s) are
    set this way:

    function addItem(form){
    var i=0;
    if (form.xxx.lengt h == 0 ){
    i=0;
    }
    else {
    i=form.xxx.leng th
    };

    if (form.xxx.style .visibility != 'visible') {
    form.xxx.style. visibility = 'visible';
    };

    form.xxx.option s[i] = new
    Option(form.sta rtProcess.optio ns(form.startPr ocess.selectedI ndex).text
    + ' to ' + form.endProcess .options(form.e ndProcess.selec tedIndex).text,
    form.startProce ss.options(form .startProcess.s electedIndex).v alue
    + ' to ' + form.endProcess .options(form.e ndProcess.selec tedIndex).value );
    } //ENd Add Item
  • kaeli

    #2
    Re: Dynamically setting an event.

    In article <9abbaed9.04090 71141.3c2ed29a@ posting.google. com>,
    david.paskiet@t-mobile.com enlightened us with...[color=blue]
    > Greeting All:
    >
    > Time to pick the collective brain cell again. I have a web page that
    > adds options to a select box on the fly. What I need to do is set the
    > onDblClick event the same way. I need to call a function when the
    > user double clicks on anything in the list box.
    >
    > ANy help would be greatly appreciated.
    >[/color]

    AFAIK, that event is only supported in MSIE.
    That said, this is how I add events for NN6 and IE6.
    Watch for word-wrapping. Modify element ID, event, and handler appropriately.

    /*************** *************** *************** **/
    /* jsEvents.js
    event handling for IE and NN
    */

    function addEvent(elemen tObject, eventName, functionObject)
    {
    if(document.add EventListener)
    {
    elementObject.a ddEventListener (eventName,
    function (evt)
    {
    functionObject( elementObject, evt);
    },
    false);
    }
    else if(document.att achEvent)
    {
    elementObject.a ttachEvent("on" + eventName,
    function ()
    {
    functionObject( elementObject);
    }
    )
    }
    }

    /*************** **END********** *************** **/

    <script type="text/javascript">
    addEvent(docume nt.getElementBy Id("myElementId "),"change" , myHandler);
    </script>

    --
    --
    ~kaeli~
    Well, aren't we just a flipping ray of sunshine?



    Comment

    • Richard Cornford

      #3
      Re: Dynamically setting an event.

      David wrote:[color=blue]
      > Time to pick the collective brain cell again. I have a web
      > page that adds options to a select box on the fly. What I
      > need to do is set the onDblClick event the same way.
      > I need to call a function when the user double clicks
      > on anything in the list box.[/color]

      If you mean double-clicking on an option in a select list then you are
      not going to be successful as IE browsers do not recognise any events on
      OPTION elements.

      In other browsers you might try:-

      select.options[index].ondblclick = functionReferen ce;

      <snip>[color=blue]
      > form.endProcess .options(form.e ndProcess.selec tedIndex).text,[/color]
      <snip> ^ ^

      I am assuming that you are writing exclusively for IE because you are
      parenthesising an argument to the - options - collection (calling it as
      a method) instead of bracketing a property name (index).

      Richard.


      Comment

      • Sensei

        #4
        Re: Dynamically setting an event.

        Sorry. I should have said that I ma doing this for an intranet with
        everyone happily using IE5.5+.



        David Paskiet
        908-642-2401

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Richard Cornford

          #5
          Re: Dynamically setting an event.

          Sensei wrote:[color=blue]
          > Sorry. I should have said that I ma doing this for an
          > intranet with everyone happily using IE5.5+.[/color]
          <snip>

          Maybe, but IE happily supports bracket notation property accessors (it
          has to as they are part of ECMAScript, and specified for use with
          collections in the W3D DOM bindings for ECMAScript) in addition to
          treating DOM collections as methods/functions.

          Even when writing exclusively for IE, if you avoid using Microsoftisms
          whenever standard direct alternatives are available you will not acquire
          a lot of bad habits that will stand in your way if you are ever called
          upon to write cross-browser code (and the attempt to write cross-browser
          code will not then give you the impression that the task is harder (and
          so more costly) than it really is).

          Richard.


          Comment

          Working...