473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with innerhtml and onchange of drop down list

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="Go od 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!

Apr 21 '06 #1
4 9802

tj*****@phenom-biz.com wrote:
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="Go od 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.

Apr 21 '06 #2
Move your onChange event into the select tag.

Apr 21 '06 #3

Martyr2 wrote:
tj*****@phenom-biz.com wrote:
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="Go od 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.


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.

Apr 21 '06 #4
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!

Apr 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Constant | last post by:
I was doing a test website where on one page somebody could select a Genre from a drop-down list and it would display every sub-listing under that specific Genre. If the user selected All it would...
5
by: Jim Bond | last post by:
Hello, I have found myself in the position of having to manage & "hack" a web site built by someone else. I am trying to make a modification to the javascript code and have been unable to get...
3
by: mtz | last post by:
Hi there, It looks like safari has a problem with innerHTML. I have to change a dropdown depending on a selection in another dropdown. When I change the selection in the first dropdown the...
2
by: chobo | last post by:
Hi, I am trying to make a dynamic menu using javascript and an xml file. The structure of the page (test.html) is in the code below. When I load up the page the drop-down list is there, so I select a...
7
by: slekshmipriya | last post by:
Hai friends.I have a pblm with my drop down list onchange event.The pblm is as follow I have a drop drown list with items 1,2 ,3 etc. On selecting an item from the drop down list i want to...
1
by: gauravtechie | last post by:
Hi all, I have a javascript that is reloading itself on every menu change, Now the problem is that the values of the product doesn`t reset itself on catalogue change, the code is <html>...
3
omerbutt
by: omerbutt | last post by:
hi there i have downloaded a prototype tooltip from http://www.nickstakenburg.com/projects/prototip/ the logic it uses is to call the script after creating the <div> for example i am using the...
1
by: ruds | last post by:
Hello, I have a JSP page in which HTML form elements are present. I have a drop down list named Country, when a user selects his country I want another drop down list to populate based on the...
2
by: swethak | last post by:
Hi, i am getting the problem when i used the onclick event in option tag.It is working fine in mozilla .But it is not working IE. Here is my code <script>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.