473,395 Members | 1,649 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,395 software developers and data experts.

Show/Hide Span based on form dropdown menu

16
Hi,
I'm new to JavaScript.
I'm trying to have a span on my form to sho some detail about the form element when the visitor is entering data. I need this to change based on the drop down menu selection. Here what is I have done sofar, but for some reason it is not working:

Expand|Select|Wrap|Line Numbers
  1. <form action="">
  2. <select onchange="if (this.selectedIndex==1){document.getElementById['box1'].style.display='block'}else {document.getElementById['box1'].style.display='none'};
  3.                   if (this.selectedIndex==2){document.getElementById['box2'].style.display='block'}else {document.getElementById['box2'].style.display='none'};">
  4. <option value="">0</option>
  5. <option value="">1</option>
  6. <option value="">2</option>
  7. <option value="">3</option>
  8. </select>
  9. <span id="box1" style="display:none">value=This is Box for 1</span>
  10. <span id="box2" style="display:none">value=This is Box for 2</span>
  11. </form>
I'm not sure what I'm doing wrong and how I can fix this.
Thanks for your help
Sep 8 '07 #1
3 5717
gits
5,390 Expert Mod 4TB
hi ...

welcome to TSDN ...

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('id');
note the round brackets :) and fix it in your code

kind regards
Sep 8 '07 #2
doc1355
16
Excellent,
Thank you so much. You guys rock.
I am adding your site to my favorites.
Sep 8 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

glad to hear you got it working ... post back to the forum anytime you have more questions ...

kind regards
Sep 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Doug van Vianen | last post by:
Hi, I am using Choice to provide a dropdown menu in an Applet. I create the Choice and then need to hide it until it is needed and then show it. I use c.hide() and c.show() where 'c' is the...
10
by: David | last post by:
Hi everyone, Hoping there are some .js/browser experts out there that can help with this weird problem. I have made a swap div routine and applied the events to menu buttons with a closer...
27
by: Nicholas Couch | last post by:
I have a little form with a couple of dynamically generated list boxes. When the user makes a selection from the first box, the second box is refreshed. When they make a selection from the second...
3
by: veganeater | last post by:
Hi, I'm wondering if there's a way that I can select which <div> to show based on the user's selection from a dropdown/listbox form. <form name="form1" method="post" action=""> <select...
3
by: RJN | last post by:
Hi The texts in the dropdown are too long and the width is not sufficient to show the entire text. Increasing the width is not an option. Is there a way to show the selected item text as a...
8
by: Andrew | last post by:
Hello, friends, We created a drop-down menu bar and a show/hide calendar web user controls mainly using javaScript and html. However, they both have the problem that they are not dispaly as...
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
1
by: proplady | last post by:
I've had this menu for some time, and periodically make changes. I've made some changes now (just some menu items), and the menu will not show up on my webpages. I know it's something simple,...
2
by: rickl2790 | last post by:
Hi All I am putting a form together and I need to be able to hide or display elements of the form based on what is selected with a select. The form is a passenger details entry form and the...
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: 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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.