FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Text area to appear on specific select tag option

 


ptolomeo
I hope someone can help me achieving the following efect on a form.

I have a select drop down list with a series of options. When the option value
is (e.g.) "other", I want a text area appear at the right side of the select area
with the cursor focused on it and with a default text on it e.g. "Write here".

I have been trying different approaches but ultimately I come to the problem
of making an input text appear from nothing an impossible task.

Am I asking too much to javascript? is it possible to make an input tag appear
on a javascript event?

Thank you a lot for any help!!
MrBlueSky
Here is a very basic example of one way to do it:

Code:

<table><tr><td>
<select id="selectme"  onchange="change()">
<option value="1">One</option>
<option value="2">Two</option>
<option value="other">Other</option>
</select>
</td><td>
<div style="display:none" id="mydiv"><textarea name="sometext" id="ta"></textarea></div>
</td></tr></table>
<script>
var visible=false;
function change() {
   if (visible) {
      document.getElementById("mydiv").style['display']="none";
      visible = false;
   } else {
      if (document.getElementById("selectme").selectedIndex != 2) return;
      document.getElementById("mydiv").style['display']="block";
      visible = true;
   }
}
</script>



Do you want something like this?
ptolomeo
Yes!! exactly what I wanted. Thank you very much!
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.