944,057 Members | Top Members by Rank

Ad:
Aug 21st, 2007
0

dropdownlist disable other dropdownlist

Expand Post »
Hi Guys

I'm a newbie in asp.net and I want to disable dropdownlist1 in my form when value "no" is selected from the <asp:ListItem> of dropdownlist2. How can I achieve that? Thanks for reply. BTW I'm using C# language.

Finch
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
finch is offline Offline
2 posts
since Aug 2007
Aug 21st, 2007
0

Re: dropdownlist disable other dropdownlist

A very simple and crude snippet:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <select name="first" id="first" onchange="if(this.value == 'no') document.getElementById('sec').disabled=true; else document.getElementById('sec').disabled=false;">
  2. <option value="yes">Yes</option>
  3. <option value="no">No</option>
  4. </select>
  5. <br /><br />
  6. <select name="sec" id="sec">
  7. <option value="yes">Yes</option>
  8. <option value="no">No</option>
  9. </select>
I would leave to you the job of putting those bunch of statements in a separate function and changing the way the function is called as per your requirement.
Last edited by ~s.o.s~; Aug 21st, 2007 at 12:58 pm.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Aug 21st, 2007
0

Re: dropdownlist disable other dropdownlist

Thank for your help mate.

Problem is that solution is perfect for html form, not asp.net - therefore I cannot use it within <br> and <td> tags in asp form. I also cannot use method onchange, web developer says that it is no supported by dropdownlist. Any ideas how to trick it? Thanks a lot for your time.

Finch

Edit: Here's the code I want to change:

<asp:View ID="View4" runat="server">
<table cellpadding="4" cellspacing="4">
<tr>
<td colspan="2"><b>Section 3 - Health and Safety Policy and Arrangements</b></td>
</tr>
<tr>
<td>3.1 Does your company have a written Health and Safety Policy?</td>
<td><aspropDownList ID="HealthPolicy" runat="server" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>Yes</asp:ListItem>
</aspropDownList>
</td>
</tr>
<tr><td>If yes, please provide us with copy of your health and safety policy. Please go to section 3.3. If No, please answer question 3.2</td></tr>
<tr>
<td>3.2 Does your company employ 5 or persons?</td>
<td><aspropDownList ID="Employ5" runat="server" Enabled="False" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>Yes</asp:ListItem>
</aspropDownList>
</td>
</tr>
Last edited by finch; Aug 21st, 2007 at 6:46 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
finch is offline Offline
2 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: How do I set linked Office files to open with full toolbar functionality?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: How to get full usernames in Active User Today scripts on forums





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC