VS 2008 Getting javascript object required error-VBForums
Results 1 to 2 of 2

Thread: Getting javascript object required error

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,421

    Getting javascript object required error

    I am getting an object required error and I understand it's because the object I am looking for doesn't exist yet, but I don't know why it doesn't exist yet. Here is my code:

    Code:
    								<tr><!-- This is the row with Effective Date -->
    									<td nowrap valign="top">
    										<asp:label id="EffectiveDateTitleLabel" runat="server" Width="120px">Effective Date:</asp:label>
    										<p></p>
    									</td>
    									<td nowrap valign="top">
                                            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                 <ContentTemplate>
                                                    <asp:dropdownlist id="EffectiveDateDropDown" runat="server" onchange="SetTextArea(this.value)"></asp:dropdownlist>
                                                </ContentTemplate>
                                                <Triggers>
                                                    <asp:AsyncPostBackTrigger ControlID="QuoteType" 
                                                        EventName="SelectedIndexChanged" />
                                                </Triggers>
                                            </asp:UpdatePanel>
    										
    									</td>
    								</tr>
    																
    								<tr><!-- This is the row with Total Employees -->
    									<td nowrap valign="top">
    										<asp:label id="TotalEmployeesLabel" runat="server" Width="120px"> Total Employees</asp:label>
    										<p></p>
    									</td>
    									<td nowrap valign="top">
    										<asp:DropDownList id="TotalEmployees" runat="server">
    											<asp:ListItem Value="" Selected="True">No preference</asp:ListItem>
    											<asp:ListItem Value="1">19 or fewer employees working for the company</asp:ListItem>
    											<asp:ListItem Value="0">20 or more employees working for the company</asp:ListItem>
    										</asp:DropDownList>
    									</td>
    								</tr>
    What I want to accomplish is when the selected effective date is greater than 01/01/2014, hide the TotalEmployees dropdownlist (and label, but for now I'm just trying to do the DDL).

    Here's the js:
    Code:
    		
    	<script type="text/javascript">
    	    function SetTextArea(selectedValue) {
    	        alert("selected value changed to " + selectedValue);
    	        var selectedDate = new Date(selectedValue);
    	        var cutoffDate = new Date("01/01/2014");
    	        if (selectedDate > cutoffDate) {
    	            var theObj = document.getElementById("TotalEmployees");    //.style.display = "none";
    	            if(!theObj) 
                        alert("Could not find TotalEmployees");
                }
    
    	    }
        </script>
    I get the alert that it could not find totalemployees. Is this because EffectiveDateDropDown is in an UpdatePanel so the two dropdowns don't exist at the same time? Or something like that?

    I don't have to use JS. I thought it would be easier than using AJAX. But it's not if it doesn't work.

    Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Getting javascript object required error

    I think you need to use PageRequestManager for custome JS inside a updatePanel.

    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.