Solved

Disable a combobox

Posted on 2003-10-29
5
1,160 Views
Last Modified: 2013-12-03
I have two combo boxes .. Status & Children .. When we open the html file, the value of Status is "Single" & Children field is disabled .. so I want that when If I select "Married" or any other value except "Single", the Children field should not be disable.

<html>
<head>
<title>Recruitment Application</title>
<script language="JavaScript" type="text/javascript">
<!--
function onFieldFocus(element) {
    if (element.disabled) {
         element.blur();
    }
}

function onPageLoad() {
    document._Recruitment.Children.disabled=true;
}

function disable_enable()
{
     if (document._Recruitment.Status.value=="Single")
     {
    document._Recruitment.Children.disabled=true;
    alert("done");
     }  
}
// -->
</script>

</head>
<body text="#000000" bgcolor="#FFFFFF" onload="onPageLoad()">

<form method="post" action=".." name="_Recruitment">

<table border=0>
 <tr>
  <td colspan=2>      Marital Information  </td>
 </tr>
 <tr>
  <td><font size="2" face="Tahoma">      </font>&nbsp</td>
  <td><font size="2" face="Tahoma">      </font>&nbsp</td>
 </tr>
 <tr>
  <td><font size="2" face="Tahoma">      </font>Marital Status: </td>
  <td><font size="2" face="Tahoma">      </font><font size="2" face="Tahoma">
<select name="Status" onchange="disable_enable()">
<option>Single
<option>Married
<option>Divorced
<option>Widowed</select>
</font>  </td>
 </tr>
 <tr>
  <td><font size="2" face="Tahoma">      </font>No. of Children: </td>
  <td><font size="2" face="Tahoma">      </font><font size="2" face="Tahoma">
<select name="Children" onfocus="onFieldFocus(this)">
<option>0
<option>1
<option>2
<option>3
<option>4
<option>5</select>
</font>  </td>
 </tr>
</table>
<br><table border=0>
 <tr>
  <td><font size="2" face="Tahoma">   </font></td>
  <td><font size="2" face="Tahoma">      </font><input type=submit value="submit" class=btn>&nbsp<input type=reset

value="reset" class=btn>  </td>
 </tr>
</table></body>
</head></form>
</body>
</html>
0
Comment
Question by:ninteen83
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
function disable_enable()
{
    if (document._Recruitment.Status.value=="Single")
    {
       document._Recruitment.Children.disabled=true;
   }  
   else
        document._Recruitment.Children.disabled=false;
   return true;
}

u may try this on
hope this can inspire u
0
 

Author Comment

by:ninteen83
Comment Utility
Okay .. by default it is "Single" .. Now when I select Married or any other .. the Children field is enabled .. but when I select back "Single" .. the Children field is still enabled ..

need help again :(

thanks ho_alan
0
 
LVL 5

Accepted Solution

by:
ho_alan earned 100 total points
Comment Utility
u have missed the option value

<select name="Status" onchange="disable_enable()">
<option value=Single>Single
<option value=Married>Married
<option value=Divorced>Divorced
<option value=Widowed>Widowed</select>
0
 
LVL 5

Expert Comment

by:ho_alan
Comment Utility
here is the full version:  :-)

<html>
<head>
<title>Recruitment Application</title>
<script language="JavaScript" type="text/javascript">
<!--
function onFieldFocus(element) {
   if (element.disabled) {
        element.blur();
   }
}

function onPageLoad() {
   document._Recruitment.Children.disabled=true;
}

function disable_enable()
{
   if (document._Recruitment.Status.value=="Single")
   {
      
       document._Recruitment.Children.disabled=true;
  }  
   else
      document._Recruitment.Children.disabled=false;
  return true;
}

// -->
</script>

</head>
<body text="#000000" bgcolor="#FFFFFF" onload="onPageLoad()">

<form method="post" action=".." name="_Recruitment">

<table border=0>
<tr>
 <td colspan=2>     Marital Information  </td>
</tr>
<tr>
 <td><font size="2" face="Tahoma">     </font>&nbsp</td>
 <td><font size="2" face="Tahoma">     </font>&nbsp</td>
</tr>
<tr>
 <td><font size="2" face="Tahoma">     </font>Marital Status: </td>
 <td><font size="2" face="Tahoma">     </font><font size="2" face="Tahoma">
<select name="Status" onchange="disable_enable()">
<option value=Single>Single
<option value=Married>Married
<option value=Divorced>Divorced
<option value=Widowed>Widowed</select>
</font>  </td>
</tr>
<tr>
 <td><font size="2" face="Tahoma">     </font>No. of Children: </td>
 <td><font size="2" face="Tahoma">     </font><font size="2" face="Tahoma">
<select name="Children" onfocus="onFieldFocus(this)">
<option value=0>0
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5</select>
</font>  </td>
</tr>
</table>
<br><table border=0>
<tr>
 <td><font size="2" face="Tahoma">   </font></td>
 <td><font size="2" face="Tahoma">     </font><input type=submit value="submit" class=btn>&nbsp<input type=reset

value="reset" class=btn>  </td>
</tr>
</table></body>
</head></form>
</body>
</html>


0
 

Author Comment

by:ninteen83
Comment Utility
ho_alan ... thanks :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now