469,306 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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 3275


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by MT | last post: by
5 posts views Thread by Richard Cornford | last post: by
1 post views Thread by Howard Jess | last post: by
4 posts views Thread by Daniel R. Rossnagel | last post: by
2 posts views Thread by Joel Byrd | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.