Trying to figure this one out. There’s a very simple script function to check the state of a checkbox on a custom ASPX form, and show or hide a table row accordingly. It works just fine in 2010. In 2013, we get the error that the function being called is undefined, and the showing/hiding don’t work. Any ideas why that would be the case? Thanks for looking!
The function definition (located as the very last element of the ASPX page, after the final </asp:Panel>
<script type=”text/javascript” language=”javascript”>
$(function ChkClosedClicked(sender) {
if ($(“input[name$=ChkClosed]”).is(‘:checked’))
$(‘#<%=trFinalEmail.ClientID %>’).show();
else
$(‘#<%=trFinalEmail.ClientID %>’).hide();
}
);
</script>
The relevant part of the table and field definitions:
<tr>
<td class=”formlabel”>
Closed?
</td>
<td class=”formfield”>
<div class=”clearfloat”>
<asp:CheckBox ID=”ChkClosed” runat=”server” AutoPostBack=”false” Checked=”false”
Text=” “ onClick=”ChkClosedClicked(this)” />
</div>
<div class=”clearfloat”>
</div>
</td>
</tr>
<tr id=”trFinalEmail” runat=”server” style=”display: none”>
<td class=”formlabel”>
Final Email
</td>
<td class=”formfield”>
<div class=”clearfloat”>
<asp:TextBox ID=”TxtFinalEmail” CssClass=”txt” runat=”server” TextMode=”MultiLine”
Rows=”6″ Columns=”20″ Width=”400px”></asp:TextBox>
</div>
<div class=”clearfloat”>
</div>
</td>
</tr>
Additionally, in SP2013 the AssetPicker.js file uses a global named $ which will conflict with your code (overwriting jQuery or vice versa).
To fully protect your code you should init your $ jQuery references within a closure:
(function($, document, window) {
window.ChkClosedClicked = function (sender) { };
})(jQuery, document, window); // jQuery resolved to $, document & window passed for performance.
Would also be better practice to use Prashanth Padebettu’s suggestion which removes the requirement on a ChkClosedClicked global method however as you said this requires additional changes.