We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

HTML Emable/Disable list boxed

prain
prain asked
on
Medium Priority
649 Views
Last Modified: 2012-05-05
Here is my scenario.

I have a list box and buttons.

1. At the start of the page I MUST set the listBox to Disable.
2. User Enters an input from a textfield, and then clicks a button. Based on  the validity of the input
   (say valid input) the listBox get enabled. Otherwise, the list box stays dsabled.

How to do this in HTML.?

prain
Comment
Watch Question

You can use a couple of JavaScript lines of code to do the job. If you paste the following lines into an empty HTML file, you will have a page with a disabled textbox, an enabled textbox, and a button. To enable the first textbox, you need to type "Hello" in the second textbox, and then click the Enable button.

________________________________________

<script LANGUAGE="JavaScript">
function ChangeEnableMode()
{
      if (document.myform.textname2.value=="Hello")
      {
            document.myform.textname1.disabled=false;
      }
}
</script>
<form action="" method="" name="myform">
<input type="text" disabled size="10" name="textname1"><BR>
<input type="text" size="10" name="textname2"><BR>
<input type="button" value="Enable" onclick="ChangeEnableMode()">
</form>

________________________________________

_______________

  Nayer Naguib

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Actually in mine, the enable/disable will happen to a listBox and not a textbox. But user inputs data into a textbox.
Well then using Nayer's example you'd simply want this:


<script LANGUAGE="JavaScript">
function ChangeEnableMode()
{
     if (document.myform.textname1.value=="Hello")
     {
          document.myform.listbox.disabled = false;
     }
}
</script>

<form name="myform" method="post" action="">
<input type="text" size="10" name="textname1"><BR>
<input type="button" value="Enable" onclick="ChangeEnableMode()"><br><br>
  <select name="listbox" disabled>
    <option value="test1">test 1</option>
    <option value="test2">test 2</option>
  </select>

</form>
Exactly. My example applies to any form control you have got. Just change the JavaScript statement to refer to the name of the desired control.

_______________

  Nayer Naguib

Author

Commented:
Hello,

I split the points b/w the two of you as poth contributed. But Nayer gets more because he threw the first close solution and apot modified that a bit.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.