473,395 Members | 1,583 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.

Display 2nd Textbox when option selected

I have a select box with about 5 options.
I need to have one of the options, when selected, display a second select
box.
The second select box is populated by a database and needs to be preloaded
so the page doesnt refresh.

How can this be done?

I guess could have the second select box displayed but disabled and it would
become active once the option is selected on the first select box.

I just have no idea how to do this.

Thanks in advance!


Jul 23 '05 #1
2 2568


Targa wrote:
I have a select box with about 5 options.
I need to have one of the options, when selected, display a second select
box.
The second select box is populated by a database and needs to be preloaded
so the page doesnt refresh.

How can this be done?

I guess could have the second select box displayed but disabled and it would
become active once the option is selected on the first select box.

I just have no idea how to do this.


HTML 4 knows an attribute named disabled for HTML form controls, it is
scripted as the property of the same name so to have a form that enables
a select if a certain option of another select is selected have a look
at the following example:

<html>
<head>
<title>disabling/enabling a form control</title>
</head>
<body>
<form name="formName">
<select name="select1"
onchange="if (this.selectedIndex == 3) {
this.form.elements.select2.disabled = false;
}
else {
this.form.elements.select2.disabled = true;
}">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
</select>
<select name="select2">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
</select>
<script type="text/javascript">
document.forms.formName.elements.select2.disabled = true;
</script>
</form>
</body>
</html>

Note that script is used to disable the select initially as a select
disabled statically with HTML would mean the user needs JavaScript
enabled to make use of the form.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Excellent example!
Worked perfectly for me - Thanks!
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40******@olaf.komtel.net...


Targa wrote:
I have a select box with about 5 options.
I need to have one of the options, when selected, display a second select box.
The second select box is populated by a database and needs to be preloaded so the page doesnt refresh.

How can this be done?

I guess could have the second select box displayed but disabled and it would become active once the option is selected on the first select box.

I just have no idea how to do this.


HTML 4 knows an attribute named disabled for HTML form controls, it is
scripted as the property of the same name so to have a form that enables
a select if a certain option of another select is selected have a look
at the following example:

<html>
<head>
<title>disabling/enabling a form control</title>
</head>
<body>
<form name="formName">
<select name="select1"
onchange="if (this.selectedIndex == 3) {
this.form.elements.select2.disabled = false;
}
else {
this.form.elements.select2.disabled = true;
}">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
</select>
<select name="select2">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
</select>
<script type="text/javascript">
document.forms.formName.elements.select2.disabled = true;
</script>
</form>
</body>
</html>

Note that script is used to disable the select initially as a select
disabled statically with HTML would mean the user needs JavaScript
enabled to make use of the form.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Jul 23 '05 #3

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

Similar topics

4
by: kindermaxiz | last post by:
//I have a form such as this: echo "<form method=\"post\" action=$php_self> <BR><INPUT TYPE=\"TEXT\" NAME=\"textbox\" SIZE=\"40\"> <BR> <select name=\"searchlist\"> <option...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
3
by: Iain Hallam | last post by:
Hi. I've been using display:none on the style property of some <option> elements in my forms, which works fine with Mozilla - as expected it removes the option from my dropdown (although it...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
1
by: Bobc003 | last post by:
Hi, I'd like to put a double drop-down menu on my webpage and instead of a redirection to a new webpage, I'd like to display the result in a new section. I'm kind of stuck and I only have a triple...
7
by: TechnoAtif | last post by:
Hi..There is again a similar problem..Now i;ve got the option values of list?menu box to show the textbox. If the option value of list is yes then the textbox is to be displayed . Can anyone...
5
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, It's been a while, I've got a small problem that I could do with your expertise on. As you know (I Think) I build websites for recruitment agencies, part of the website includes a job...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...
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...

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.