Forum Moderators: open

Message Too Old, No Replies

Show extra 'other' field on choosing Other in dropdown

form dropdown other

         

maupie

8:47 am on Feb 14, 2005 (gmt 0)

10+ Year Member



Hello,

I can remember seeing a dropdown list which could do the following:

There are a number of regular 'select options', and the last one is 'Other'. Nothing special until now. But when I chose that option (Other), a new textfield appeared on the right where you could type your 'Other' text. Just to be clear: it wasn't there in the first place, so it must be some javascript to display it as chosen the last select option.

Has somebody seen this before, or does somebody know how to make it?

It would really help me out and I think that many of us could use it.

Kind regards from the Netherlands,
Maurice Luimes.

le_gber

10:04 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

You're right it's done with javascript.

what you need to do is have something like that:

in your html form:

...
<option value="option 1"> option 1 </option>
<option value="option 2"> option 2 </option>
<option value="other"> other </option>
...

then where you want the box to appear:

<input type="text" value="please enter more info" name="otherhidden" class="hiddenbox">

And then in your js file you need a function that will toggle the visibility of the otherhidden box when the drop down changes to the other value (with an onchange function assigned to the drop down)

Hope this helps

Leo

maupie

10:31 am on Feb 14, 2005 (gmt 0)

10+ Year Member



Hi Leo,

Thanx, you helped me quite a bit.

Unfortunately, I still have one small problem.

Now, whenever I change my dropdown list, the extra field appears right away. And it should only appear when the option 'Other' is selected. Of course, the problem is that the onchange script is placed in the select-tag. So when you change, the text-box appears right away. I tried to put the onchange-tag in the option-tag, but that didn't work.

How do I get it to work so that the extra text-field only appears when you select 'Other'. And even better, when you go back to select another item, the text-field disappears once again?

Thanx in advance,
Maurice.

maupie

10:34 am on Feb 14, 2005 (gmt 0)

10+ Year Member



Leo,

Just to be sure, the script (Overig stands for Other):

<script type='text/javascript'>
function showother( id ) {
document.all.Overig.style.visibility = 'hidden';

document.all.Overig.value = '';

document.all[ id ].style.visibility = 'visible';
document.all[ id ].focus();
}
</script>

and the HTML:

<select name="Onderwerp" class="tabelinvultekst" onchange="showother( 'Overig' )">
<option value="">Kies hier
<option value="Gelaatsverzorging">Gelaatsverzorging
<option value="Maquillage">Maquillage
<option value="Massage">Massage
<option value="Lichaamsverzorging">Lichaamsverzorging
<option value="Ontharing">Ontharing
<option value="Manicure">Manicure
<option value="Pedicure">Pedicure
<option value="Overig">Overig...
</select>
<input type="text" name="Overig" class="tabelinvultekst" style="visibility:hidden">

maupie

4:45 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



hi leo,

i just found it out.

thank you for your help!

kind regards,
maurice.