469,900 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

enable textbox with select option

4
hi everybody,

i am trying to enable a textbox object when the user select an option from dropdown list.

Can anybody help please?
Jul 19 '10 #1
4 2298
acoder
16,027 Expert Mod 8TB
You can use onchange on the select element to call a function. In this function, get the text box with document.getElementById() and then set its disabled property to false.

If you can't get it to work, post your code
Jul 19 '10 #2
fmuddy
4
thanks acoder i did it but with radio button.
Jul 29 '10 #3
Expand|Select|Wrap|Line Numbers
  1. <form name="form1">
  2.     Select Subject ::    <select name="subject">
  3.             <option value="php" onclick="hide_other()">PHP </option>
  4.             <option value="asp"  onclick="hide_other()">ASP </option>
  5.             <option value="html" onclick="hide_other()">HTML </option>    
  6.             <option value="java"  onclick="hide_other()">JAVA</option>    
  7.             <option value="other" onclick="view_other()">Other</option>                            
  8.     </select>
  9.     <input type="text" name="other_suject" id="other_subject" style="display:none;"/>
  10. </form>
  11. <script type="text/javascript">
  12.     function view_other()
  13.     {    
  14.         document.getElementById("other_subject").style.display="block";
  15.     }    
  16.     function hide_other()
  17.     {
  18.         document.getElementById("other_subject").style.display="none";    
  19.     }
  20. </script>
May 17 '12 #4
acoder
16,027 Expert Mod 8TB
Seems very inefficient (adding an onclick event to each individual option). Add an onchange to the select element instead.
May 23 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Michael Hoffmann | last post: by
4 posts views Thread by Jeff Anderson | last post: by
9 posts views Thread by Susan Bricker | last post: by
2 posts views Thread by shagy | last post: by
1 post views Thread by kirke | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.