Connecting Tech Pros Worldwide Forums | Help | Site Map

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

zzzbla@gmail.com
Guest
 
Posts: n/a
#1: Apr 24 '06
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


Randy Webb
Guest
 
Posts: n/a
#2: Apr 24 '06

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


zzzbla@gmail.com said the following on 4/24/2006 1:21 PM:[color=blue]
> 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?[/color]

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/
zzzbla@gmail.com
Guest
 
Posts: n/a
#3: Apr 27 '06

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


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:[color=blue]
> zzzbla@gmail.com said the following on 4/24/2006 1:21 PM:[color=green]
> > 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?[/color]
>
> 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/[/color]

Randy Webb
Guest
 
Posts: n/a
#4: Apr 27 '06

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


zzzbla@gmail.com 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?
[color=blue]
> hi,
>
> what if there are already functions that handle the event (either by
> <select onchange="functionname">) or the equivalent
> ....elements["elementname"].onchange?[/color]

Did you test it to see? And if so, what happened?
[color=blue]
> how can i make sure that it's my function that runs and not the others?[/color]

You can start by testing it.

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

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/
Closed Thread


Similar JavaScript / Ajax / DHTML bytes