0

I have written a jquerwery on drop down selected fecthing it value ina label. It is not working in application page.Same is working in normal aspx page. Can you please help me what iam doing wrong.

Jquery code:

<script type="text/javascript" src="/Converttopdf/_layouts/Emailjs/1.7.2.jquery.min.js">


        $(document).ready(function () {
            $('#ddlTaskFrequency').change(function () {

                $("#lblNameChange").text($("#ddlTaskFrequency").val());
                 return false;
            })
        });   
</script>

My ASPX PAGE

<td>
            <asp:DropDownList ID="ddlTaskFrequency" runat="server">
                <asp:ListItem Selected="True" Text="Daily" Value="Daysat"></asp:ListItem>
                <asp:ListItem Text="Weekly" Value="Weeksat"></asp:ListItem>
                <asp:ListItem Text="Monthly" Value="Monthsat"></asp:ListItem>
            </asp:DropDownList>
        </td>
<td>
<asp:Label ID="lblNameChange" runat="server" Text="" 
                CssClass="TextSize"></asp:Label>
</td>

4 Answers 4

1

You can try putting wait mechanism for loading of the jquery file before execution of the script.

Use following method ExecuteOrDelayUntilScriptLoaded(setAttributes, "your_js_filename.js"); in .js file to wait till all the files are loaded and see.

Hope this helps!

1

Load jQuery using a ScriptLink control:

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

    <SharePoint:ScriptLink ID="ScriptLink1" Name="Emailjs/1.7.2.jquery.min.js" Localizable="false" LoadAfterUI="false" runat="server" />

    <script type="text/javascript">
        $(document).ready(function () {
            $('#ddlTaskFrequency').change(function () {

                $("#lblNameChange").text($("#ddlTaskFrequency").val());
                 return false;
            })
        });   
    </script>
</asp:Content>

You can find more details in this recording of my talk on SharePoint 2010 Client-Side Development with the JSOM and jQuery

0

First of all, sepparate the code.

<script type="text/javascript" src="/Converttopdf/_layouts/Emailjs/1.7.2.jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#ddlTaskFrequency').change(function () {

            $("#lblNameChange").text($("#ddlTaskFrequency").val());
             return false;
        })
    });  
    //if this keeps failing, use the tag above
    ExecuteOrDelayUntilScriptLoaded(MyFunction, "jquery.js");
    //but you need to modify jquery to notify when it has been loaded...
    //one last thing, you can use RequireJS if this keeps failing...
</script>
0

I tried like this and it worked likle charm. I think we have to use Client id ....

<script language="javascript" type="text/javascript" src="/Converttopdf/_layouts/Emailjs/1.7.2.jquery.min.js"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        ////Dropdownlist Selectedchange e

        $('#' + '<%=this.ddlTaskFrequency.ClientID  %>').change(function()
        {
        $('#' + '<%=this.lblNameChange.ClientID  %>').text($('#' + '<%=this.ddlTaskFrequency.ClientID  %>').val());
        return false;
        })
        });

</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.