While developing a web part for Sharepoint I came across an issue where I needed to have Javascript manipulate elements in the web part. I searched around for the best way to include my Javascript file as part of my Sharepoint solution and came across many articles but I couldn't get their methods to work until I came across this one:
http://www.codeproject.com/KB/aspnet/MyWebResourceProj.aspx
I'm not sure why but "Page.ClientScript.GetWebResourceUrl" seems to work for me but "Page.ClientScript.RegisterClientScriptResource" as per this article doesn't.
Sunday, June 15, 2008
Wednesday, June 11, 2008
Dynamically set the onclick attribute of a html element using Javascript
I've been trying to dynamically set the onlick attribute of a span element in Javascript.
I tried a couple of things including:
var newNavNode = document.createElement("span");
newNavNode.onclick = "horizontalNavClick('"+nodeValue+"');" ;
But this wasn't working as a reference to the function was needed and not a string.
I googled and found this post: http://codingforums.com/archive/index.php?t-55356.html
And modified my script to:
var newNavNode = document.createElement("span");
newNavNode.onclick = new Function("horizontalNavClick('"+nodeValue+"')");
This worked like a charm. Thanks Willy Duitt!
Happy scripting everyone!
I tried a couple of things including:
var newNavNode = document.createElement("span");
newNavNode.onclick = "horizontalNavClick('"+nodeValue+"');" ;
But this wasn't working as a reference to the function was needed and not a string.
I googled and found this post: http://codingforums.com/archive/index.php?t-55356.html
And modified my script to:
var newNavNode = document.createElement("span");
newNavNode.onclick = new Function("horizontalNavClick('"+nodeValue+"')");
This worked like a charm. Thanks Willy Duitt!
Happy scripting everyone!
Subscribe to:
Posts (Atom)