Passing Parameters to a Jquery script

Sherry Collins asked on May 31, 2015 18:23

I am adding a "likes" button to my individual blogs. I have added the button through the transformation like such "span id="newlikes" target=_blank> anchor href="#">Likes endanchor end span"

When the user clicks the likes button I want to pass the user name and document name to a jquery script.

In this particular transformation, I have access to both pieces of information (the user name and document name) and can get them with a BlogFunctions.GetUserName(Eval("CurrentUser")) and Eval("BlogPostTitle") from within the transformation.

How do I get these two data points to a jquery.

Correct Answer

Jim Spillane answered on May 31, 2015 20:02

Hi Sherry.

In your transformation you can add the two fields using data attributes like...

<span id="newlikes" data-currentuser="<%# BlogFunctions.GetUserName(Eval("CurrentUser")) %>" data-blogposttitle="<%# Eval("BlogPostTitle")%>">Like</span>

Then in jQuery you can reference them...

$("#newlikes").click(function() {
  alert( "User : " + $(this).data("currentuser") + "\nTitle : " + $(this).data("blogposttitle") );
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.