Link to home
Start Free TrialLog in
Avatar of kp_y
kp_y

asked on

disable/enable textbox

i have a drop-down box and a textbox
how do i disable the textbox by default, then if user select certain value in the textbox, the textbox will be enabled to allow user to enter value.  
ASKER CERTIFIED SOLUTION
Avatar of son_robin
son_robin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomasdodds
thomasdodds

NOTE: disabled controls will not be posted in ASP ...

minimize the javascript and disable the textbox right in the HTML:

<input type=text id=txtMyText DISABLED>
<select id=cboMySelect onChange="javascript:enableTextBox();">
 <option value="1">1</option>
 <option value="2">2</option>
 <option value="3">3</option>
</select>

<script language=javascript>
<!--
  function enableTextBox()
  {
    var idx = document.forms[0].cboMySelect.selectedIndex;

    //any old selected value
    if (idx != -1)
    {
      document.forms[0].txtMyText.disabled = false;
    }

    // or for a specific value
    if (document.forms[0].cboMySelect.options[idx].value == "2")
    {
      document.forms[0].txtMyText.disabled = false;
    }
  }
//-->
</script>

to alleviate cross-browser issues, try coding according to the DOM -- saves headaches

thomasdodds
This question has been abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
   In the absence of responses, I may recommend DELETE unless it is clear
   to me that it has value as a PAQ.  Silence = you don't care
</note>

Cd&
It is time to clean this abandoned question up.

I am putting it on a clean up list for CS.

<recommendation>
points to son_robin

</recommendation>

If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Cd&

per recommendation

SpideyMod
Community Support Moderator @Experts Exchange