RadhaKrishnaKiJaya
asked on
Enable Disable Drop Down
Hi Experts,
I want to enable/disable a drop down on C#. I am able to do it in Java Script. But, I need to do it on C# too during page load and on click of Submit button. Below is my code. I have three drop downs. I need to enable the 3rd drop down i.e. id="OrgUnit" if WorkCountry = "DE" selected. For other countries, it should be disabled. Please advice.
Thank you in advance.
<html>
<head>
<script type="text/javascript">
function makeDisable(){
var x=document.getElementById( "mySelect" )
x.disabled=true
}
function makeEnable(){
var x=document.getElementById( "mySelect" )
x.disabled=false
}
function EnableOrgUnit(){
var x=document.getElementById( "WorkCount ry")
var y=document.getElementById( "lblOrgUni t")
var z=document.getElementById( "OrgUnit")
alert('Working: ' + x.value);
if (x.value == "DE")
{
y.disabled=false
z.disabled=false
}
else
{
y.disabled=true
z.disabled=true
}
}
</script>
</head>
<body>
<table cellSpacing="0" cellPadding="0" width="400" border="0">
<form id="Form1" runat="server">
<TBODY>
<tr>
<td>
<asp:dropdownlist id="mySelect" tabIndex="15" runat="server" Width="150px">
<asp:ListItem Value="Apple" Selected="True">Apple</asp :ListItem>
<asp:ListItem Value="Banana">Banana</asp :ListItem>
<asp:ListItem Value="Orange">Orange</asp :ListItem>
</asp:dropdownlist>
</td>
<td><input type="button" onclick="makeDisable()" value="Disable list"></td>
<td><input type="button" onclick="makeEnable()" value="Enable List"></td>
</tr>
<tr>
<td width="118" style="WIDTH: 118px"><FONT class="label">Work Country:</FONT><span class="requiredField">&nbs p;*</span> </td>
<td width="70%"><asp:dropdownl ist class="Required" id="WorkCountry" tabIndex="14" runat="server" Width="120px" onchange="EnableOrgUnit(); ">
<asp:ListItem Value="No Selection" Selected="True">--- Select one ---</asp:ListItem>
<asp:ListItem Value="US">US</asp:ListIte m>
<asp:ListItem Value="DE">DE</asp:ListIte m>
</asp:dropdownlist></td>
</tr>
<tr>
<td width="118" style="WIDTH: 118px"><span class="requiredField">
<asp:Label id="lblOrgUnit" runat="server" Font-Bold="True" ForeColor="#1A659E">Org Unit:</asp:Label></span></ td>
<td width="70%"><asp:dropdownl ist id="OrgUnit" tabIndex="15" runat="server" Width="150px">
<asp:ListItem Value="No Selection" Selected="True">--- Select one ---</asp:ListItem>
<asp:ListItem Value="Aerospace Lubeck">Aerospace Lubeck</asp:ListItem>
<asp:ListItem Value="Aerospace Hamburg">Aerospace Hamburg</asp:ListItem>
<asp:ListItem Value="Aerospace Finkenwerder">Aerospace Finkenwerder</asp:ListItem >
</asp:dropdownlist></td>
</tr>
</form>
</TBODY>
</table>
</body>
</html>
I want to enable/disable a drop down on C#. I am able to do it in Java Script. But, I need to do it on C# too during page load and on click of Submit button. Below is my code. I have three drop downs. I need to enable the 3rd drop down i.e. id="OrgUnit" if WorkCountry = "DE" selected. For other countries, it should be disabled. Please advice.
Thank you in advance.
<html>
<head>
<script type="text/javascript">
function makeDisable(){
var x=document.getElementById(
x.disabled=true
}
function makeEnable(){
var x=document.getElementById(
x.disabled=false
}
function EnableOrgUnit(){
var x=document.getElementById(
var y=document.getElementById(
var z=document.getElementById(
alert('Working: ' + x.value);
if (x.value == "DE")
{
y.disabled=false
z.disabled=false
}
else
{
y.disabled=true
z.disabled=true
}
}
</script>
</head>
<body>
<table cellSpacing="0" cellPadding="0" width="400" border="0">
<form id="Form1" runat="server">
<TBODY>
<tr>
<td>
<asp:dropdownlist id="mySelect" tabIndex="15" runat="server" Width="150px">
<asp:ListItem Value="Apple" Selected="True">Apple</asp
<asp:ListItem Value="Banana">Banana</asp
<asp:ListItem Value="Orange">Orange</asp
</asp:dropdownlist>
</td>
<td><input type="button" onclick="makeDisable()" value="Disable list"></td>
<td><input type="button" onclick="makeEnable()" value="Enable List"></td>
</tr>
<tr>
<td width="118" style="WIDTH: 118px"><FONT class="label">Work Country:</FONT><span class="requiredField">&nbs
<td width="70%"><asp:dropdownl
<asp:ListItem Value="No Selection" Selected="True">--- Select one ---</asp:ListItem>
<asp:ListItem Value="US">US</asp:ListIte
<asp:ListItem Value="DE">DE</asp:ListIte
</asp:dropdownlist></td>
</tr>
<tr>
<td width="118" style="WIDTH: 118px"><span class="requiredField">
<asp:Label id="lblOrgUnit" runat="server" Font-Bold="True" ForeColor="#1A659E">Org Unit:</asp:Label></span></
<td width="70%"><asp:dropdownl
<asp:ListItem Value="No Selection" Selected="True">--- Select one ---</asp:ListItem>
<asp:ListItem Value="Aerospace Lubeck">Aerospace Lubeck</asp:ListItem>
<asp:ListItem Value="Aerospace Hamburg">Aerospace Hamburg</asp:ListItem>
<asp:ListItem Value="Aerospace Finkenwerder">Aerospace Finkenwerder</asp:ListItem
</asp:dropdownlist></td>
</tr>
</form>
</TBODY>
</table>
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solution deserves 9 out of 10. I don't know how it is calaculated to 7.6. Thanks again.
ASKER
Thank you all for your wonderful help. It worked great in no time. VSS, thank you again for taking my code and working on it. A simple thank is not enough for the help you did at the time of need. Plese keep doing so. Thank you again. Bye now.