up vote 1 down vote favorite
share [fb]

My ascx looks like this:

<SharePoint:ScriptLink ID="ScriptLink1" runat="server" Name="/_layouts/1033/MyProject/js/test.js"/>
test: <input id="example" /> 

test.js looks like this:

$(document).ready(function () {
    alert("test");
});

In MyProject I have a folder called js and in that folder I have test.js

I was under the impression that when I debugged my webpart it would pop up an alert taht said "test" but it does nothing. Am I doing something wrong here?

link|improve this question

feedback

1 Answer

up vote 3 down vote accepted

Do you have a reference to jquery on the page before the test.js include? Try using http://spc3.codeplex.com/wikipage?title=ClientScript&referringTitle=Home

Are there any script errors, is jquery loaded, try testing this before the alert:

if (typeof jQuery == 'undefined') {   
    alert('jQuery not loaded')   
}

Try adding this at the top of your include to make sure the include path is right

alert('test.js loaded')   

Is it a VS2010 project? You need to add one of the sharepoint mapped folders, say LAYOUTS, and make your folder stucture under that (can't start with a folder called js)

MyProject/LAYOUTS/1033/MyProject/js/test.js
link|improve this answer
Sorry, I left the jQuery part out. It is in my actual code, just didn't copy it over. I have not added the LAYOUTS folder yet so that is probably the problem. Is it just as simple as creating a folder called LAYOUTS or is there more to it? – Abe Miessler Apr 11 at 15:15
For anyone interested in how to add Mapped Folders see this link: msdn.microsoft.com/en-us/library/ee231521.aspx – Abe Miessler Apr 12 at 3:00
feedback

Your Answer

 
or
required, but never shown

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