SharePoint 2020

The Vision for a Future of Clarity

Using Javascript URL in Calculated Columns

If you’re looking at using Javascript in a calculated column to call a URL, here’s a method that’s quick and simple to apply.

I found that when I attempted to run this inside a calculated column, the javascript url path removes the ” ” and therefore won’t run.

HTML Example of URL

<a onclick='javascript:openDialog("/server/site/CSSdocument.pdf");javascript:return false;' href="#" target=_self>

<img src="/server/site/CSS_Page_001.jpg" alt="" ></a>

So you could run the html inside a html file linked to the Content Editor Web Part first to make sure your Javascript works on the page, then add the Custom List with the calculated column below.

Instructions

First, create two ‘single line of text’ columns, each containing the following text as default value

jscript1

onclick='javascript:openDialog("

jscript2

");javascript:return false;'

Then, I have two versions of syntax you can use. Make sure you change “The data type returned from this formula is:” to Number (1, 1.0, 100)  This will convert your column to html.

Calculated Column Version 1

="<a "&jscript1&""&FileName&""&jscript2&" href='#' title='Title' target='_self'><img src='"&Thumbnail&"' alt=''></a>"

Calculated Column Version 2

=CONCATENATE("<DIV><a ",jscript1,"",FileName,"",jscript2," href='#' title='book' target='_self'><img src='",Thumbnail,"' alt=''></a></DIV>")

So from the examples above, each “jscript” column will be replaced with it’s code and which will use the “FileName” column as it’s URL.

It’s not as Dynamic as I would like, so this would suit a Site Owner who familiar with Javascript.

Any questions if it doesn’t work and would like assistance, please comment below.

Advertisements

February 20, 2013 - Posted by | SharePoint 2010 | ,

6 Comments »

  1. Hey Sandy, Your code was stripped out of the comments.
    I haven’t had to use a button with onclick event in a calculated column before.
    What are you trying to run with the onclick button? Maybe I know of a work-around,

    Comment by Brett | July 25, 2013 | Reply

  2. I’ve managed to insert a button in to my task list so far using the below code:

    =CONCATENATE(“”)

    I want to call the java script on button click is it possible? can you please help me

    Thanks,
    SANDY

    Comment by sandy | July 25, 2013 | Reply

  3. Hi Rebecca,
    I’m no expert in Calculated Columns, I have taught myself from trial and error and Googling what specifically I need answered. I’ll send you an email so you can send me your Calculated Column code and I can take a look if you like?

    Comment by Brett | June 13, 2013 | Reply

  4. I have a column that has a formula in it. I created a calculated column that copies the other column into the calculated field. However all it is doing is copying the formula and not actually doing the calculation. Do you think if I put the formula into separate columns and do a concatenate that that may work. Or do you have any other suggestions as to how I may get the column to actually do the calculations. I know the formula works because if I type it into the calculated column it does what is supposed to do. The reason I didn’t just type it into the calculated column is that each list item has a different formula. Any help is greatly appreciated.

    Comment by Rebecca | June 13, 2013 | Reply

  5. HI Andy, you can just add the call to the Title column in the HREF like this:

     href='"&Title&"'

    This Post was actually for my own records but it’s good to see you get some use out of it.

    Comment by Brett | June 7, 2013 | Reply

  6. Great Article! Can we add the Title URL to the HREF? If so how?

    Comment by Andy | June 7, 2013 | Reply


Post a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: