Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialstephen rosso
4,419 PointsError says cannot read property of NULL for all elements
I am trying to create a request sting and add the value of a check box (var = PrintDetails) I do not know hwy my application does not see the check box. it just says cannot read property 'Checked' of NULL //JavaScript Code
$(document).ready(function () { console.log("Im ready now!"); });
function updateReport(response, responseStatus, request) { console.log('Updating Report...'); $("#InformReportGeneratedDiv").css("display", "block"); }
function generateReportCallout(requestString) { alert(requestString); $.ajax({ type: 'POST', url: url, data: requestString, success: updateReport, error: function (response) { alert("Something went wrong!"); } }); }
function generateEmptyLocationsUnassignedReport() { console.log("Generating Empty Locations Unassigned report..."); var printDetails = document.getElementById('BodyContent_Content_PrintDetails').checked ? "True" : "False"; var requestString = appname + "&PRGNAME=Empty Locations Unassign Cover" + "&ARGUMENTS=-L" + printDetails; generateReportCallout(requestString); }
//.aspx page <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <script type="text/javascript" src="JS/reports.js"></script> <div class="row"> <div class="col text-left text-center"> <h2><%: Title %></h2> <br /> </div> </div> <div id="InformReportGeneratedDiv" style="display: none;"> <h1>Your Report is being generated. Visit 'My Reports' Page to view it when it is ready.</h1> </div> <div class="text-center"> <asp:DropDownList ID="ReportDDL" runat="server" AutoPostBack="true" Font-Size="X-Large" Width="300px" Height="50px"> <asp:ListItem Selected="True" Value="">/asp:ListItem <asp:ListItem Value="Unassigned Locations aka Locations where Part Number field is empty">Empty Locations Unassigned/asp:ListItem /asp:DropDownList </div>
<br />
<h1 class="text-center"><%: ReportDDL.SelectedItem.Value %></h1>
<asp:Panel Visible='<%# String.Equals(ReportDDL.SelectedItem.Value, "Unassigned Locations aka Locations where Part Number field is empty") %>' runat="server" ID="GenerateEmptyLocUnassignedPanel">
<div class="container-fluid">
<div class="row pad-t-20">
<div class="col-md-4 col-md-offset-4 text-center">
<label class="two-em-text">Print Details?</label><asp:CheckBox ID="PrintDetails" runat="server" />
</div>
</div>
<div class="row pad-t-20">
<div class="col-md-2 col-md-offset-5 text-center">
<input type="button" value="Generate Report" class="btn btn-primary btn-large" onclick="generateEmptyLocationsUnassignedReport();">
</div>
</div>
</div>
</asp:Panel>
<div class="text-center pad-t-40">
<a href="MyReports" runat="server" class="btn btn-default" role="button">View my reports</a>
</div>
2 Answers
Steven Parker
231,899 PointsI'm not sure what you mean by "all elements", I only see one reference to "checked".
But it might be that the asp-mutated ID isn't quite what you're expecting. Have you tried using the browser devtools to see exactly what the ID is?
You could also try a different kind of selector function to access the element without using the ID.
stephen rosso
4,419 PointsUsed Chrome developer tools to find the asp mutated ID of the element.
stephen rosso
4,419 Pointsstephen rosso
4,419 PointsSteven! You're a legend! Issue was the asp-mutated Id was not what i thought it was. I found the mutated name of the input in the developer tools. Thanks for the input!
Steven Parker
231,899 PointsSteven Parker
231,899 Pointsstephen rosso — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!