HTML Emable/Disable list boxed

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
prainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nayernaguibCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prainAuthor Commented:
Actually in mine, the enable/disable will happen to a listBox and not a textbox. But user inputs data into a textbox.
0
apotropaicCommented:
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>
0
nayernaguibCommented:
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
0
prainAuthor 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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.