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

Making Form Elements Appear and Disappear

I have a case where the user can select several choices from my 1st <SELECT>
element. The user's choice on the 1st <SELECT> effects what the possible
choices are for the 2nd element. Currently the 2nd element is a <TEXT>
input, but I'd like to be able to make it a <TEXT> element when certain
items are selected from the 1st <SELECT> and a <SELECT> when other choices
are selected. Is there a way to either change an element from <TEXT> to
<SELECT> (and back), or to make a <SELECT> or <TEXT> element disappear
without re-writing the entire page?

Thanks!

Hal
Jul 20 '05 #1
1 3415


Hal Vaughan wrote:
I have a case where the user can select several choices from my 1st <SELECT>
element. The user's choice on the 1st <SELECT> effects what the possible
choices are for the 2nd element. Currently the 2nd element is a <TEXT>
input, but I'd like to be able to make it a <TEXT> element when certain
items are selected from the 1st <SELECT> and a <SELECT> when other choices
are selected. Is there a way to either change an element from <TEXT> to
<SELECT> (and back), or to make a <SELECT> or <TEXT> element disappear
without re-writing the entire page?


It doesn't depend on the type of the element, if you have a reference to
an element in the HTML page and if the browser like Netscape 6+, IE4+,
Opera 7 supports toggling the CSS display property of an element then
you can do
if (element.style) {
element.style.display = 'none';
}
to hide the element and
if (element.style) {
element.style.display = '';
}
to show it again.
If you are scripting form controls inside a <form> container then the
usual way to access another control element object is alike
<form ...>
...
<select name="select0"
onchange="if (this.selectedIndex == 3) {
var element = this.form.elements.select1;
if (element.style) {
element.style.display = 'none';
}
}">
...
</select>
...
<select name="select1" ...>
if (this.s

--

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

Jul 20 '05 #2

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

Similar topics

4
by: MT | last post by:
Hi all, this sounds like an easy enough thing to do, but after spending 45 minutes searching google and various javascript sites I can't find out how to make a textfield (textbox or whatever you...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
17
by: KS | last post by:
I got 2 inputs in a form where I want check if start > end. Seems like it just compare the first number when I got this code in javascript "if(document.all.start > document.all.end)" How do i...
1
by: Howard Jess | last post by:
Apparently, form elements of type <input type="image" src="...> are not included in the form's elements collection. I don't understand why not; according to DOM2, all form control elements...
3
by: Bryan Capps | last post by:
I have a text box control on a form, the value of which is calculated (concatenated) from entries on a subform. Accordingly, I've set the control's locked property to true and the tab stop...
4
by: Daniel R. Rossnagel | last post by:
As I can hide the bar of I title of a window daughter maximized within form MDI Already I have proven with different types from borders, hiding thebuttons to maximize, to diminish and control box,...
1
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the...
2
by: Joel Byrd | last post by:
I want to get a red outline around different divs on a page when I hover the mouse over them, and then have the red outline disappear on mouse out (basically to indicate that various elements on...
11
by: TechnoAtif | last post by:
Here is the other one..This requires a textbox to open while clicking of a radiobutton in one part and in the other part on the click of a list/menu. I want that..as I click the second...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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...
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...

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.