473,738 Members | 3,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi

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>
</select>

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

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

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,
Steve
Jul 20 '05 #1
6 148643
SilverSioux
1 New Member
Steve,
Did you ever get a response to your request? I need to do something similar. Please email me at ljhibbard@doit. nv.gov.
Thanks.
Linda
Aug 10 '05 #2
MrK
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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Show/Hide</title>
<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';
}
}
// ]]>
</script>
</head>

<body>
<table width="340" cellspacing="0" cellpadding="2" >
<thead>
<tr>
<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>
</select>
</td>
</tr>
</thead>
<tfoot>
<tr>
<td class="align-center" colspan="2"><in put type="submit" name="submit" value="Update" /> <input type="reset" value="Reset" /></td>
</tr>
</tfoot>
<tbody id="text" style="display: none;">
<tr>
<td class="title">T ext Color:</td>
<td class="field">< input type="text" name="color" size="8" maxlength="7" /></td>
</tr>
</tbody>
<tbody id="image" style="display: none;">
<tr>
<td class="title">I mage:</td>
<td class="field">< input type="file" name="image" size="10" /></td>
</tr>
<tr>
<td class="title">X Coordinates:</td>
<td class="field">< input type="text" name="x_coordin ates" size="5" /></td>
</tr>
<tr>
<td class="title">Y Coordinates:</td>
<td class="field">< input type="text" name="y_coordin ates" size="5" /></td>
</tr>
<tr>
<td class="title">T ext Color:</td>
<td class="field">< input type="text" name="color" size="8" maxlength="7" /></td>
</tr>
</tbody>
<tbody>
<tr>
<td class="title">D isplay:</td>
<td class="field">
<select name="display">
<option value="visitors ">Visitors</option>
<option value="hits">Hi ts</option>
</select>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Feb 16 '06 #3
preston2003
4 New Member
Thanks for the JScript. It worked well for me
Mar 23 '06 #4
Allan
1 New Member
Thanks for the JScript. It worked well for me
Hello,

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
nausa
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.

Thanks,
Amy
Apr 14 '06 #6
mnemonic
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>
</select>

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>
</select>

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

1
2077
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.
2
4116
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?
1
1885
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>...
6
1947
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>
2
1549
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,...
3
24567
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...
6
4322
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....
0
1266
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>
0
1447
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...
0
8968
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, 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...
0
9473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
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, 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...
1
6750
isladogs
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...
0
4569
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...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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 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.