Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Making Form Elements Appear and Disappear

Reply
Thread Tools

Making Form Elements Appear and Disappear

 
 
Hal Vaughan
Guest
Posts: n/a
 
      12-24-2003
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-25-2003


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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
navigation menu causes vertical scroll bar to appear/disappear Larz Javascript 5 05-26-2009 07:47 PM
Tkinter: Making a window disappear Claus Tondering Python 4 10-10-2006 08:42 AM
Outlook Express Messages Disappear, Bookmarks in Internet Explorer Disappear rchrdcarlisle@NOTyahoo.com Computer Support 19 07-30-2006 09:41 PM
Form images don't appear in form.elements Howard Jess Javascript 1 10-18-2004 07:15 PM
Controls move when scroll appear/ disappear problem Tamir Kamara ASP .Net 1 02-29-2004 06:11 AM



Advertisments