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

Z

zzzbla

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
 
R

Randy Webb

(e-mail address removed) 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;
 
Z

zzzbla

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 said:
(e-mail address removed) 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;
 
R

Randy Webb

(e-mail address removed) 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top