Connecting Tech Pros Worldwide Forums | Help | Site Map

beginner:dynamic form field

nescio
Guest
 
Posts: n/a
#1: May 18 '06
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,



Erwin Moller
Guest
 
Posts: n/a
#2: May 18 '06

re: beginner:dynamic form field


nescio wrote:
[color=blue]
> hello,[/color]

Hi,
[color=blue]
>
> i have a form with a listbox;[/color]

What is a listbox?
Do you mean a SELECT?
[color=blue]
> 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,[/color]

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
Randy Webb
Guest
 
Posts: n/a
#3: May 18 '06

re: beginner:dynamic form field


nescio said the following on 5/18/2006 7:51 AM:[color=blue]
> 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?[/color]

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.
[color=blue]
> i have looked on the internt but all i found where very complicated examples
> that i did not unserstand at all.[/color]

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/
nescio
Guest
 
Posts: n/a
#4: May 18 '06

re: beginner:dynamic form field



thanks for your help, i now have something to work on


Closed Thread