468,720 Members | 1,715 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

beginner:dynamic form field

hello,

i have a form with a listbox;
in this listbox people can choose between 'yes' and 'no';

if the choose 'yes' i want a new text field to appear.

if the choose 'no' nothing happens;

but how do i do this?

i have looked on the internt but all i found where very complicated examples
that i did not unserstand at all.

i am looking for a very straight forward example, or solution.

thanks,
May 18 '06 #1
3 1372
nescio wrote:
hello,
Hi,

i have a form with a listbox;
What is a listbox?
Do you mean a SELECT?
in this listbox people can choose between 'yes' and 'no';

if the choose 'yes' i want a new text field to appear.

if the choose 'no' nothing happens;

but how do i do this?

i have looked on the internt but all i found where very complicated
examples that i did not unserstand at all.

i am looking for a very straight forward example, or solution.

thanks,


Sounds like homework to me, so I'll just give you a few hints.

1) how to find which option is selected?
look up: selectedIndex
Learn how to adres a SELECT in a form.
This will end up like: document.forms.myForm.mySelect.selectedIndex
2) How to hide a part of the page?
Look up: DIV or SPAN and pay attention to a property named 'display' which
should be 'none' to hide something and 'block' (for DIV) or 'inline' (for
SPAN).

Hope that helps.

Regards,
Erwin Moller
May 18 '06 #2
nescio said the following on 5/18/2006 7:51 AM:
hello,

i have a form with a listbox;
in this listbox people can choose between 'yes' and 'no';

if the choose 'yes' i want a new text field to appear.

if the choose 'no' nothing happens;

but how do i do this?
One of several ways. You can make that text field always be there and
make it visible/hidden based on the value of the select element.
i have looked on the internt but all i found where very complicated examples
that i did not unserstand at all.


Complicated examples of hiding/showing an element? I don't believe that.

<select onchange="hideElement('divToHide',this.value)">
<option value="visible">Yes
<option value="hidden">No
</select>
<div id="divToHide" style="visibility:visible">
<input name="myInput">
</div>

<script type="text/javascript">
function hideElement(elem,visibilityMode){
document.getElementById(elem).style.visibility = visibilityMode;
}
</script>

That is it at it's simplest. You could also use createElement and
appendChild to create the element but that can get messy in a hurry
trying to remove it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 18 '06 #3

thanks for your help, i now have something to work on
May 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Chung Hang Shum | last post: by
6 posts views Thread by MROPARTNER | last post: by
23 posts views Thread by Russ Chinoy | last post: by
4 posts views Thread by Jessica | last post: by
5 posts views Thread by nescio | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.