?
Solved

HTML Emable/Disable list boxed

Posted on 2006-03-29
5
Medium Priority
?
618 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
0
Comment
Question by:prain
  • 2
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
nayernaguib earned 360 total points
ID: 16325140
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
 

Author Comment

by:prain
ID: 16325251
Actually in mine, the enable/disable will happen to a listBox and not a textbox. But user inputs data into a textbox.
0
 
LVL 1

Assisted Solution

by:apotropaic
apotropaic earned 140 total points
ID: 16325434
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
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16325530
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
 

Author Comment

by:prain
ID: 16325916
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question