Disable 2nd Pulldown

I think you'll need some knowledge of ASP.NET to help me with this one.

How can I gray out my second pulldown if the user changes the original value of the first pulldown? I'm trying to use a JavaScript (added in my header); maybe if I had this part right getElementById('supplierDrop2').  it would work?

<script language="javascript">
function FreqChanged()
{
Form1.getElementById('supplierDrop2').Enabled=false
}
</script>


I have added (what I believe is) the correct code to this line:

    <asp:DropDownList ID="supplierDrop" DataTextField="HowOft" DataValueField="FreqID" Runat="server" OnChange="javascript:FreqChanged();"></asp:DropDownList>

************************************************************

My original code:


          <script language="vb" runat="server">
          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
               'Put user code to initialize the page here
               If (Not Page.IsPostBack) Then
                    listfoods()
                    FQl()
               End If
          End Sub
             
          Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
           listfoods()
           FQl()
                     
    End Sub

         Private Sub listfoods()

              Dim objconn As New SqlConnection("Mystring")
               objconn.Open()
               try
               Dim MemID
          MemID = (Request.Cookies(“sy”)(“MemID"))        
               Dim objcmd As New SqlCommand("ChFQ" , objconn)
               objCmd.CommandType = CommandType.StoredProcedure
              Dim retValue As Integer
              objcmd.Parameters.Add("@MemID", SqlDbType.Int).Value = MemID
               Dim retParam As New SqlParameter("@RETURN_VALUE", SqlDbType.Int)
retParam.Direction = ParameterDirection.ReturnValue
objcmd.Parameters.Add(retParam)

objcmd.ExecuteScalar()

retValue = Cint(Cint(objcmd.Parameters("@RETURN_VALUE").Value))
If retValue = 300 then
'no daily foods
else

Dim dr As SqlDataReader
               dr = objcmd.ExecuteReader()
               Dim currentNick as string = ""
               Dim currentNoNick as string = ""
Dim dt as DataTable = new DataTable()
dt.Columns.Add("HowOft")
dt.Columns.Add("FreqID")
dt.Columns.Add("DayName")
dt.Columns.Add("DWID")
dt.Columns.Add("FoodID")
dt.Columns.Add("FoodDesc")
dt.Columns.Add("HMID")
dt.Columns.Add("HMNickName")
dt.Columns.Add("NickDisplay")
dt.Columns.Add("NoNickDisplay")

Do While (dr.Read())
    Dim row as DataRow = dt.NewRow()
 row("HowOft")=dr("HowOft")
 row("FreqID")=dr("FreqID")
 row("DayName")=dr("DayName")
   row("DWID")=dr("DWID")
     row("FoodID")=dr("FoodID")
    row("FoodDesc")=dr("FoodDesc")
         row("HMID")=dr("HMID")
     if   (currentNoNick =("")) and (dr("HMNickName") = ("Please Select"))
    row("NoNickDisplay") = "Anyone's Foods"
        currentNoNick="Anyone"
        elseif (currentNoNick="Anyone")
        row("NoNickDisplay")=""
        end if
        if (currentNick <> dr("HMNickName")) and (dr("HMNickName") <> ("Please Select")) ' if this is the first time
        row("NickDisplay") = dr("HMNickName")+"'s Foods"
        currentNick=dr("HMNickName")
    Else
        row("NickDisplay")=""
    End If
      dt.Rows.Add(row)
Loop
       dataList1.DataSource = dt
       dataList1.DataBind()
       dr.Close
end if
               finally
               objConn.Close()
               objConn.Dispose()
               end try
             
               End Sub
               
     
Private Sub datalist_item_bind(ByVal sender As Object, ByVal e As DataListItemEventArgs)
              If ((e.Item.ItemType = ListItemType.Item) or ( e.Item.ItemType = ListItemType.AlternatingItem)) Then
                    Dim droplist As DropDownList
                   
                    droplist = CType(e.Item.FindControl("supplierDrop"), DropDownList)
                    Dim objconn As New SqlConnection("Mystring")
                    objconn.Open()
                    try
                    Dim objcmd As New SqlCommand("FQEd", objconn)
                    objCmd.CommandType = CommandType.StoredProcedure
                    Dim dr As SqlDataReader
                    dr = objcmd.ExecuteReader()              
                    droplist.DataSource = dr
                    droplist.DataTextField = "HowOft"
                    droplist.DataValueField= "FreqID"
                    droplist.DataBind()
                   
          if not droplist.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "FreqID").ToString()) is nothing then
     droplist.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "FreqID").ToString()).Selected = True
end if
              dr.Close()
                     
                    finally
                    objConn.Close()
                   objConn.Dispose()
                    end try    
      End If          
             
  If ((e.Item.ItemType = ListItemType.Item) or ( e.Item.ItemType = ListItemType.AlternatingItem)) Then
  Dim droplist2 As DropDownList
                 
                    Dim objconn As New SqlConnection("Mystring")
                    objconn.Open()
                      try
                    droplist2 = CType(e.Item.FindControl("supplierDrop2"), DropDownList)
                                     
                    Dim objcmd2 As New SqlCommand("TP", objconn)
                    objCmd2.CommandType = CommandType.StoredProcedure
                    Dim dr3 As SqlDataReader
                    dr3 = objcmd2.ExecuteReader()              
                    droplist2.DataSource = dr3
                    droplist2.DataTextField = "DayName"
                    droplist2.DataValueField= "DWID"
                    droplist2.DataBind()
                   
          if not droplist2.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "DWID").ToString()) is nothing then
     droplist2.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "DWID").ToString()).Selected = True
end if
             dr3.Close()
             
             
                    finally
                    objConn.Close()
                   objConn.Dispose()
                    end try

               End If
          End Sub
         
                     
    Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim objconn As New SqlConnection("Mystring")
        'asked from open to close
        objconn.Open()
        Dim objcmd As New SqlCommand("UpCh", objconn)
        objCmd.CommandType = CommandType.StoredProcedure
        objcmd.Parameters.Add("@FoodID", SqlDbType.Int)
        objcmd.Parameters.Add("@FreqID", SqlDbType.Int)
        objcmd.Parameters.Add("@DWID", SqlDbType.Int)

        For Each dlItem As DataListItem In DataList1.Items
            Dim txtProdName As TextBox = CType(dlItem.FindControl("txtprodname"), TextBox)
            Dim droplist As DropDownList = CType(dlItem.FindControl("supplierDrop"), DropDownList)
            Dim droplist2 As DropDownList = CType(dlItem.FindControl("supplierDrop2"), DropDownList)
            Dim spanFoodID As HtmlGenericControl = CType(dlItem.FindControl("spanProdID"), HtmlGenericControl)
            objcmd.Parameters("@FoodID").Value = spanFoodID.InnerHtml
            objcmd.Parameters("@FreqID").Value = CInt(droplist.SelectedValue)
            objcmd.Parameters("@DWID").Value = CInt(droplist2.SelectedValue)

            objcmd.ExecuteNonQuery()            
        Next
        objconn.Close()
    End Sub
         
          </script>
     </HEAD>
     <body>
     
          <br>
          <div style="TEXT-ALIGN: center">
               <table class="main">
                    <tbody>
                         <tr align="center">
                              <td colspan="5">
                                   
                              </td>
                         </tr>
                         <tr align="center">
                              <td colspan="2">
                                   <form id="Form1" method="post" runat="server">
                                        <asp:DataList id="DataList1" DataKeyField="FoodID" runat="server" OnItemDataBound="datalist_item_bind">
                                             <ItemTemplate>
                                                  <tr align="center">
                                                       <td align="left">
                                                            <span style="display:none" id="Span1" runat="server">
                                                                 <%# DataBinder.Eval(Container.DataItem, "HMID") %>
                                                            </span>
                                                            <div class="formtextsm"><%# DataBinder.Eval(Container.DataItem, "NoNickDisplay") %>
                                                                 <%# DataBinder.Eval(Container.DataItem, "NickDisplay") %>
                                                                 &nbsp;</div>
                                                       </td>
                                                       <td width="5">&nbsp;</td>
                                                       <td align="left">
                                                            <span style="display:none" id="spanProdID" runat="server">
                                                                 <%# DataBinder.Eval(Container.DataItem, "FoodID") %>
                                                            </span>
                                                            <div class="formtextsmbld"><%# DataBinder.Eval(Container.DataItem, "FoodDesc") %>&nbsp;</div>
                                                       </td>
                                                       <td width="5">&nbsp;</td>
                                                       <td>
                                                            <asp:DropDownList ID="supplierDrop" DataTextField="HowOft" DataValueField="FreqID" Runat="server"></asp:DropDownList>
                                                            <asp:DropDownList ID="supplierDrop2" DataTextField="DayName" DataValueField="DWID" Runat="server"></asp:DropDownList>
                                                       </td>
                                                  </tr>
                    </tbody>
                    </ItemTemplate> </asp:DataList>
                    <br>
                    <asp:Button id="cmdSubmit" runat="server" Text="Submit!" OnClick="cmdSubmit_Click"></asp:Button></FORM></TD></TR>
               </table>
          </div>
     </body>
</HTML>
LVL 1
net_susanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

smaccariCommented:
First, modify your JS function:

<script language="javascript">
function FreqChanged()
{
document.getElementById('supplierDrop2').disabled=true;
}
</script>

And maybe you should use this on your asp.net control:

<asp:DropDownList ID="supplierDrop" DataTextField="HowOft" DataValueField="FreqID" Runat="server" OnClientChange="FreqChanged();"></asp:DropDownList>

(mybe add a clientid attribute too, not sure though)
0
net_susanAuthor Commented:
'document.getElementById(...)' is null or not an object
0
smaccariCommented:
Can you check in the generated page source code (right click->view source in browser) the generated id for your supplierDrop2 dropdown?
If it's not supplierDrop2, try to add the clientid attribute as i suggested:

<asp:DropDownList ID="supplierDrop2" ClientID="supplierDrop2" DataTextField="DayName" DataValueField="DWID" Runat="server"></asp:DropDownList>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

net_susanAuthor Commented:
<select name="DataList1:_ctl11:supplierDrop2" id="DataList1__ctl11_supplierDrop2" ClientID="supplierDrop2">

Like this nothing happens
OnClientChange="FreqChanged();"

Like this
OnChange="javascript:FreqChanged();"  it tries to fire, but it still says:

'document.getElementById(...)' is null or not an object


0
smaccariCommented:
This should work then:

<script language="javascript">
function FreqChanged()
{
document.getElementById('DataList1__ctl11_supplierDrop2').disabled=true;
}
</script>

By the way, it's strange that you cannot generate a specific id with clientid, i thought you could do this is asp.net controls.
0
net_susanAuthor Commented:
That works...

Problem is each pulldown is given its own ID:
DataList1__ctl0_supplierDrop2
DataList1__ctl1_supplierDrop2

I'm starting to think there is no way to do this.
0
net_susanAuthor Commented:
It always coordinates with the first pulldown, though

"DataList1:_ctl0:supplierDrop"
0
net_susanAuthor Commented:
Is something like this possible?

if document.getElementById('DataList1__ctl0_supplierDrop2').SelectedValue != 4 then
document.getElementById('DataList1__ctl0_supplierDrop2').disabled=true;

else document.getElementById('DataList1__ctl1_supplierDrop2').SelectedValue != 4 then
document.getElementById('DataList1__ctl1_supplierDrop2').disabled=true;
else
'do nothing
end if
0
net_susanAuthor Commented:
Oh, that's not what I meant. Sorry.

Is something like this possible?

if document.getElementById('DataList1__ctl0_supplierDrop').SelectedValue != 4 then
document.getElementById('DataList1__ctl0_supplierDrop2').disabled=true;

else document.getElementById('DataList1__ctl1_supplierDrop').SelectedValue != 4 then
document.getElementById('DataList1__ctl1_supplierDrop2').disabled=true;
else
'do nothing
end if
0
smaccariCommented:
Like this then:

if (document.getElementById('DataList1__ctl0_supplierDrop2').value != 4)
document.getElementById('DataList1__ctl0_supplierDrop2').disabled=true;
else if (document.getElementById('DataList1__ctl1_supplierDrop2').SelectedValue != 4)
document.getElementById('DataList1__ctl1_supplierDrop2').disabled=true;

But there is something i missed i think. Maybe you could explain what you want to achieve exactly, and maybe tell more about the page context?
0
net_susanAuthor Commented:
I was posting at the same time you were, I think my last post may help.
0
net_susanAuthor Commented:
Ta da!

Now I guess I'll just do this a bunch of times:

{
if (document.getElementById('DataList1__ctl0_supplierDrop').value != 4)
document.getElementById('DataList1__ctl0_supplierDrop2').disabled=true;
else if (document.getElementById('DataList1__ctl0_supplierDrop').value = 4)
document.getElementById('DataList1__ctl0_supplierDrop2').disabled=false;

if (document.getElementById('DataList1__ctl1_supplierDrop').value != 4)
document.getElementById('DataList1__ctl1_supplierDrop2').disabled=true;
else if (document.getElementById('DataList1__ctl1_supplierDrop').value = 4)
document.getElementById('DataList1__ctl1_supplierDrop2').disabled=false;
}
0
smaccariCommented:
Ok good JS syntax for your code:

if (document.getElementById('DataList1__ctl0_supplierDrop').value != 4)
document.getElementById('DataList1__ctl0_supplierDrop2').disabled=true;
else if (document.getElementById('DataList1__ctl1_supplierDrop').SelectedValue != 4)
document.getElementById('DataList1__ctl1_supplierDrop2').disabled=true;



0
net_susanAuthor Commented:
Is there a way to say "if exists" so I can repeat this script a bunch of times without it coming up with an error?

Like... if there is a ctl50, otherwise, ignore this part

(document.getElementById('DataList1__ctl50_supplierDrop').
0
smaccariCommented:
Else, try to do this in your ASP.NET DropDown supplierDrop:

<asp:DropDownList ID="supplierDrop" DataTextField="HowOft" DataValueField="FreqID" Runat="server" OnChange="if (this.value != 4) document.getElementById(this.id +'2').disabled=true"></asp:DropDownList>
0
smaccariCommented:
Maybe you'll have to reenable the second field if value not 4:

<asp:DropDownList ID="supplierDrop" DataTextField="HowOft" DataValueField="FreqID" Runat="server" OnChange="if (this.value != 4) document.getElementById(this.id +'2').disabled=true; else document.getElementById(this.id +'2').disabled=false;"></asp:DropDownList>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
net_susanAuthor Commented:
This rocks!

<asp:DropDownList ID="supplierDrop" DataTextField="HowOft" DataValueField="FreqID" Runat="server" OnChange="if (this.value != 4) document.getElementById(this.id +'2').disabled=true; else document.getElementById(this.id +'2').disabled=false;"></asp:DropDownList>
0
smaccariCommented:
So no more need of the function FreqChanged ;)
0
net_susanAuthor Commented:
Keep an eye out for a very similar question, please. I'll post a link to it here (might be tomorrow).
0
net_susanAuthor Commented:
Yes, I had just about lost hope. This is not my first attempt at finding an answer.  :)
0
net_susanAuthor Commented:
Nevermind, I figured it out for my other page. Thank you so much!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.