Solved

Disable a combobox

Posted on 2003-10-29
5
1,162 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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)
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…

776 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