Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable a combobox

Posted on 2003-10-29
5
Medium Priority
?
1,169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…

722 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