Problem with innerhtml and onchange of drop down list

T

tjonsek

I have two drop down boxes on a form. One feeds the second a list
options based on user selection. With the second drop down, I want code
that displays dynamic text in a <div> based on whatever the user
selects.

So far, it doesn't seem to be firing.
I am only testing the functionality because I have quite a bit of text
to display depending on the users input and want to get it working
first before I bother typing everything.

Here is what I have so far:
(Second drop down box code)
<SELECT id="SubCat" NAME="SubCat">
<Option value="" onChange="ViewComparison();" >Product
Description</option>
</SELECT>
<div id="prodTable">Test</div>

Javascript:
function ViewComparison(){
document.getElementById('prodTable').innerHTML="Good Afternoon";
}

I have spent most of my programming life in asp/vbscript due to my
previous employers standards so I am fairly new to javascript.

Any help is appreciated.
Thanks!
 
M

Martyr2

I have two drop down boxes on a form. One feeds the second a list
options based on user selection. With the second drop down, I want code
that displays dynamic text in a <div> based on whatever the user
selects.

So far, it doesn't seem to be firing.
I am only testing the functionality because I have quite a bit of text
to display depending on the users input and want to get it working
first before I bother typing everything.

Here is what I have so far:
(Second drop down box code)
<SELECT id="SubCat" NAME="SubCat">
<Option value="" onChange="ViewComparison();" >Product
Description</option>
</SELECT>
<div id="prodTable">Test</div>

Javascript:
function ViewComparison(){
document.getElementById('prodTable').innerHTML="Good Afternoon";
}

I have spent most of my programming life in asp/vbscript due to my
previous employers standards so I am fairly new to javascript.

Any help is appreciated.
Thanks!

The onChange event needs to be in your SELECT opening tag, not on the
options themselves.

<SELECT id="SubCat" NAME="SubCat" onChange="ViewComparison()">

That should get you going.
 
M

Martyr2

Martyr2 said:
The onChange event needs to be in your SELECT opening tag, not on the
options themselves.

<SELECT id="SubCat" NAME="SubCat" onChange="ViewComparison()">

That should get you going.

By the way, you should also add a few more options because the event
only fires when you actually change options. If you have only one
option, then it can't change.
 
T

tjonsek

Ok - that's a case of me NOT paying attention.
But, sometimes you look at something long enough you stop seeing it.

My options are added dynamically.
Thanks for the help!
 

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,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top