473,834 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/Hide text and form field based on drop down selection


I'm trying to show/hide a simple piece of text and a text field on a
form based on what choice is made from a drop down box.

<select name="dropdown" size="1">
<option selected value="">Please make a selection</option>
<option value="1">Choic e 1</option>
<option value="2">Choic e 2</option>
<option value="3">Choic e 3</option>
<option value="4">Other </option>

i.e. if Choice 2 is selected I'd like to display a new <tr> with the

<td>New text field:</td>
<td><input name="newField" type="text size="20"></td>

if any other choices are made, I don't want to display anything.
I've tried several onchange() functions but can't achieve what I'm
looking for.

Any help would be appreciated,
Jul 20 '05 #1
6 148684
1 New Member
Did you ever get a response to your request? I need to do something similar. Please email me at ljhibbard@doit. nv.gov.
Aug 10 '05 #2
1 New Member
Try this script. It will hide/show table rows based on a selection. you can put whatever you want in the tbody areas.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
// <![CDATA[
function display(obj,id1 ,id2) {
txt = obj.options[obj.selectedInd ex].value;
document.getEle mentById(id1).s tyle.display = 'none';
document.getEle mentById(id2).s tyle.display = 'none';
if ( txt.match(id1) ) {
document.getEle mentById(id1).s tyle.display = 'block';
if ( txt.match(id2) ) {
document.getEle mentById(id2).s tyle.display = 'block';
// ]]>

<table width="340" cellspacing="0" cellpadding="2" >
<td class="title">T ype:</td>
<td class="field">
<select name="type" onchange="displ ay(this,'text', 'image');">
<option>Pleas e select:</option>
<option value="image">I mage</option>
<option value="text">Te xts</option>
<option value="invisibl e">Invisible </option>
<td class="align-center" colspan="2"><in put type="submit" name="submit" value="Update" /> <input type="reset" value="Reset" /></td>
<tbody id="text" style="display: none;">
<td class="title">T ext Color:</td>
<td class="field">< input type="text" name="color" size="8" maxlength="7" /></td>
<tbody id="image" style="display: none;">
<td class="title">I mage:</td>
<td class="field">< input type="file" name="image" size="10" /></td>
<td class="title">X Coordinates:</td>
<td class="field">< input type="text" name="x_coordin ates" size="5" /></td>
<td class="title">Y Coordinates:</td>
<td class="field">< input type="text" name="y_coordin ates" size="5" /></td>
<td class="title">T ext Color:</td>
<td class="field">< input type="text" name="color" size="8" maxlength="7" /></td>
<td class="title">D isplay:</td>
<td class="field">
<select name="display">
<option value="visitors ">Visitors</option>
<option value="hits">Hi ts</option>
Feb 16 '06 #3
4 New Member
Thanks for the JScript. It worked well for me
Mar 23 '06 #4
1 New Member
Thanks for the JScript. It worked well for me

I'm having the same problem, I'm working with xsl, but it should be +/- the same.
The update and reset doesn't do anything, does it?
I mean, the whole example doesn't do anything but show the dropdown and the buttons, right?

And can you post your example too please?
Mar 29 '06 #5
1 New Member
This code would also work great for me except if I put it in a form tags

<form></form> in order to send it to an email box to get the field values the code stops working. Is there any way to get this code to work with adding the form tags in or is there another way to send the form to an email without having the form tags.

Apr 14 '06 #6
1 New Member
what if i want to show/hide a dropdown menu after choosing from the selection and replaces it by another dropdown menu?

For example:

Here's the first dropdown menu:
<select name="signallin g">
<option value="fx">FX?</option>
<option value="pri">PRI </option>

after choosing FX? option, it will disappear and then replaces by another dropdown menu.

Here's the second dropdown menu that should appear:
<select name="fx">
<option value="fx0">FX0 </option>
<option value="fxs">FXS </option>

And ofcourse, it should have a reset button to return to its original state which hides the second dropdown menu and be replaced by the first one.

Hope that you could help me on this.

Thanks a lot!
Jun 10 '06 #7

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

Similar topics

by: InvisibleMan | last post by:
Hi, Thanks in advance... I want to test two form fields: ConversionValue (text field) convert (Select Dropdown: Index 0 = True - 1 = False) Essentially, If ConversionValue is Blank, but convert is True Then give an error and set convert to false... Or if ConversionValue is blank and convert is false - skip it.
by: Sybre | last post by:
I have a script which reads a file and generates a list for a drop-down selection box. However, I want to be able to change which option is selected when certain buttons are clicked - how can I do this?
by: bvlmv | last post by:
Hello, relatively new to programming and just trying to create a simple asp page. I have the following drop down menu on a html page and when submitting i would like to call out on asp what someone has selected. <select size="1" name="type"> <option value="Prospect">Prospect</option> <option value="Suspect">Suspect</option> <option value="Qualified">Qualified</option> <option value="Proposed">Proposed</option>...
by: bvlmv | last post by:
Hello, relatively new to programming and just trying to create a simple asp page. I have the following drop down menu on a html page and when submitting i would like to call out on asp what someone has selected. <select size="1" name="type"> <option value="Prospect">Prospect</option> <option value="Suspect">Suspect</option> <option value="Qualified">Qualified</option>
by: bbatson | last post by:
Hello, Does anyone have any advice as to how to limit a drop-down selection in a table? For example, suppose I have two tables - essentially a one-to-many relationship. One table is "Southeastern States" with about 12 states or so. The other table is "Cities", with about 200 cities within these states. I am using the "Lookup" function in a different table where the user (via a form) chooses the state and city. After selecting the city,...
by: steveninfl | last post by:
Hello , I am using MS Access 2000. I have a Table called Transactions, I have created a form for this table, one of the fields on the form is a combo box with the row source type as value list. In this combo box field that I call "Transaction type" the user must select a value from the drop down list. What I want to do is based on the selection of the "Transaction type" field, if the user should select a transaction type of ADHOC or...
by: Palehorse | last post by:
I'd like to apologize upfront for me saying "I'm not a programer", I'm sure you all hear this a hundred times a day. Unfortunately, in this case, it's true. I've been working on trying to figure out a particular problem I've had for years and now I find I need to get it situated as soon as possible. So I turn to you kind folks, the experts, to give me a little hand holding, guidance and wisdom as to how to accomplish what it is I'm trying to do....
by: So Confused | last post by:
I have a drop down selection menu on an HTML form. I want to display 1 answer, for a few selection options.... and another answer for the rest of the options. Example code is below: How Much Are You Worth In Total Assets (Savings, Equity, Stocks, 401K, Car, Home, Anything of Value, etc...)? <select name="assets"> <option value="$0 - $15K">$0 - $15K</option> <option value="$15K - $50K">$15K - $50K</option>
by: Alex Fung | last post by:
When I use GotFree Cards (http://www.got-free-ecards.com) to send free e-cards, I come across a problem when selecting the future date for sending the card. The webpage uses javascript and the date for sending the e-card can be chosen by the user in a drop-down selection list. However, the month of date cannot not be displayed properly (i.e. showing 24-???-2010). I am using Window XP Professional SP3 and the problem still persists after I...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.