Attaching javascript event to a built in advance html file...

Discussion in 'Javascript' started by zzzbla@gmail.com, Apr 24, 2006.

  1. Guest

    Hi,

    I need to attach a javascript function I wrote to the onChange event of
    a <select> tag. However, I'm using a 3rd party tool that creates the
    html files - it only lets me add bits of html to it, I can't touch the
    elements it produces, so I can't just add an onChange="myfunction"
    attribute to that <select> tag. I can't change the onload attribute of
    the <body> tag.

    How can I run code that attached my function to that event?

    Thanks in advance,
    R. Green
    , Apr 24, 2006
    #1
    1. Advertising

  2. Randy Webb Guest

    said the following on 4/24/2006 1:21 PM:
    > Hi,
    >
    > I need to attach a javascript function I wrote to the onChange event of
    > a <select> tag. However, I'm using a 3rd party tool that creates the
    > html files - it only lets me add bits of html to it, I can't touch the
    > elements it produces, so I can't just add an onChange="myfunction"
    > attribute to that <select> tag. I can't change the onload attribute of
    > the <body> tag.
    >
    > How can I run code that attached my function to that event?


    Does your select have a name or id attribute?

    If so, simply add an onchange event to it:

    document.forms['formID'].elements['selectName'].onchange=functionToExecuteOnChange;

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Apr 24, 2006
    #2
    1. Advertising

  3. Guest

    hi,

    what if there are already functions that handle the event (either by
    <select onchange="functionname">) or the equivalent
    ....elements["elementname"].onchange? how can i make sure that it's my
    function that runs and not the others?

    Randy Webb wrote:
    > said the following on 4/24/2006 1:21 PM:
    > > Hi,
    > >
    > > I need to attach a javascript function I wrote to the onChange event of
    > > a <select> tag. However, I'm using a 3rd party tool that creates the
    > > html files - it only lets me add bits of html to it, I can't touch the
    > > elements it produces, so I can't just add an onChange="myfunction"
    > > attribute to that <select> tag. I can't change the onload attribute of
    > > the <body> tag.
    > >
    > > How can I run code that attached my function to that event?

    >
    > Does your select have a name or id attribute?
    >
    > If so, simply add an onchange event to it:
    >
    > document.forms['formID'].elements['selectName'].onchange=functionToExecuteOnChange;
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    , Apr 27, 2006
    #3
  4. Randy Webb Guest

    said the following on 4/27/2006 3:10 AM:

    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?

    > hi,
    >
    > what if there are already functions that handle the event (either by
    > <select onchange="functionname">) or the equivalent
    > ....elements["elementname"].onchange?


    Did you test it to see? And if so, what happened?

    > how can i make sure that it's my function that runs and not the others?


    You can start by testing it.

    window.onload = resetSelectOnChange(){
    document.forms['formID'].elements['selectName'].onchange=functionToExecuteOnChangeThatWillSupersedeAnyOtherThatWasAssignedBeforeNowAndWillExecuteUnlessYouRedefineAnotherOne;
    }

    Note the lack of () on the function name.
    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Apr 27, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cowboy \(Gregory A. Beamer\)

    Attaching to event in container object

    Cowboy \(Gregory A. Beamer\), Oct 24, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    367
    Cowboy \(Gregory A. Beamer\)
    Oct 28, 2003
  2. williamc

    Auto-advance in html form input boxes

    williamc, Apr 27, 2004, in forum: Javascript
    Replies:
    3
    Views:
    172
    williamc
    Apr 27, 2004
  3. mike
    Replies:
    3
    Views:
    157
  4. yawnmoth
    Replies:
    2
    Views:
    177
    yawnmoth
    Dec 24, 2005
  5. David Mark
    Replies:
    1
    Views:
    709
    dhtml
    Dec 17, 2011
Loading...

Share This Page