Solved

Disable a combobox

Posted on 2003-10-29
5
1,161 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
ID: 9648371
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
ID: 9648403
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
ID: 9648443
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
ID: 9648448
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
ID: 9648610
ho_alan ... thanks :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

867 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