enable textbox with select option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fmuddy
    New Member
    • Mar 2010
    • 4

    enable textbox with select option

    hi everybody,

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

    Can anybody help please?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can use onchange on the select element to call a function. In this function, get the text box with document.getEle mentById() and then set its disabled property to false.

    If you can't get it to work, post your code

    Comment

    • fmuddy
      New Member
      • Mar 2010
      • 4

      #3
      thanks acoder i did it but with radio button.

      Comment

      • Bharat383
        New Member
        • Aug 2011
        • 93

        #4
        Code:
        <form name="form1">
        	Select Subject ::	<select name="subject">
        			<option value="php" onclick="hide_other()">PHP </option>
        			<option value="asp"  onclick="hide_other()">ASP </option>
        			<option value="html" onclick="hide_other()">HTML </option>	
        			<option value="java"  onclick="hide_other()">JAVA</option>	
        			<option value="other" onclick="view_other()">Other</option>							
        	</select>
        	<input type="text" name="other_suject" id="other_subject" style="display:none;"/>
        </form>
        <script type="text/javascript">
        	function view_other()
        	{	
        		document.getElementById("other_subject").style.display="block";
        	}	
        	function hide_other()
        	{
        		document.getElementById("other_subject").style.display="none";	
        	}
        </script>
        Last edited by acoder; May 23 '12, 04:01 PM. Reason: Added [code] tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Seems very inefficient (adding an onclick event to each individual option). Add an onchange to the select element instead.

          Comment

          Working...