You are viewing limited content. For full access, please sign in.

Question

Question

Insert a variable into hyperlink

asked on September 23, 2015 Show version history

I am looking to place a link on a Laserfiche Form that will dynamically change based on another field value.  Here is the scenario - A user opens an application, and chooses a Position from a drop-down list, which populates a number of other fields via Lookup.  One field populates with an EntryID value that I would like to pass to a weblink URL.  I attempted to use the code found [Here], but was unable to make it work for my scenario.  Below is a picture of my form, followed by the code I am starting with, but cannot get to work properly.  As you can see, the field 'Job Description' holds the EntryID, that I would like to append to the end of my weblink URL housed in the 'Job Description' link.  

Code: 

$(document).ready(function(){
$('#Field27').blur(function(){  //This is the Position Applying For field because this will trigger the 'Job Description' Input field to change
    
  var baseURL = $('#Field34');  //This is the ID of the HTML field
  var doc_id = $('#q35 input').val() ; //This is the Job Description Input that changes with the Position Applying For
  doc_id.appendTo(baseURL);
});
  })

The result I'm looking for is: http://serverurl/weblink8/Browse.aspx?dbid=0&startid=DOC_ID but want it to appear as a link with 'Job Description' as the verbiage.  

Any help is much appreciated!

Nate

0 0

Answer

SELECTED ANSWER
replied on September 24, 2015 Show version history

Ah! I've got you now sorry!

Using .innerHTML should work as shown in the screenshot attached. Please note though that this is a javascript function rather than JQuery so you'll probably have to use the javascript selector (also shown in screenshot). This function will also overwrite any HTMLcurrently in the custom HTML input pannel, but is the only way I can really think of doing it :/

This should also work if you put it inside the blur function you had on your first post to dynamically change the link when data is added.

Hopefully this helps!

Dan

1 0
replied on February 23, 2016

Dan,

I'm trying to implement this code in my form. For some reason the num variable is not passing thru into the link. Any idea why? my code:

$(document).ready(function () {
  	var num = $(".num input").val();
	var target = 'target="_blank"'; //Add this in to get link to open in new tab
  	var link = "<a " + target + "href='http://www.wherever.com?startid=" + num + "'>This is the link</a>";
  	document.getElementById("q9").innerHTML = link;
});

And here is an image of the two fields I'm using:

I'm trying to get it to work on this test form before putting it into the actual form... so any thoughts on why this isn't passing the #q8 input into the url? It currently opens a new tab to http://www.wherever.com?startid=

 

Thanks

0 0
replied on February 24, 2016 Show version history

Hi David,

I think all you're missing is the on blur function to run the code when the field value is changed. Try this:

$(document).ready(function(){
   $(".num input").on("blur", function () {
       var num = $(".num input").val();
       var target = 'target="_blank"'; //Add this in to get link to open in new tab
       var link = "<a " + target + " href='http://www.wherever.com?startid=" + num + "'>This is the link</a>";
       document.getElementById("q9").innerHTML = link;
   });
});

Hope this is what you were looking for!

Cheers, Dan.

1 0
replied on April 20, 2018

Hi Dan

I'm interested in this for a project I have on the go, but unfortunately not a coder. Is there a way to get a sample form from you with this working so I can see how all the fields are set up, and how the Custom HTML is defined. If not maybe some screen shots. Anything is helpful. FYI, I'm running Forms 10.3.1 in case the code has changed over the versions. Thanks

0 0
replied on April 23, 2018 Show version history

Steve,

Here's what I have working for me.  

1.  I have a 'Customer HTML' field on my form with ID q34

2.  I have a 'Single Line' field that will contain my variable.  This is set by a data-lookup that contains a Laserfiche Entry ID.  This will also be my trigger point so I added a CSS Class of 'job' so that I can use this in my code later.  

3.  In the CSS & Javascript section, you'll need to create the function and my code looks something like this:

  function jobDesc()
  {
	var doc_id = $('#q35 input').val() ; //This is my variable (LF Entry ID) that will change via data lookup
	var open = '&openfile="true"'; //Because my url is calling weblink, this is a parameter you can pass through to Open the file
	var target = 'target="_blank"'; // This sets the hyperlink to open in a new tab
	var openLink = doc_id + open; //Combining two tokens above for easier retrieval below
	var link = "<a " + target + "href='YourURLHere?dbid=db&id=" + openLink +"'>HyperLinkText</a>";//Create your hyperlink here
	document.getElementById("q34").innerHTML = link; //Insert your hyperlink into my Custom HTML Field (q34 in my case)
	}

Now that the function is created, you need to call this when a field changes and/or any other set of JS events.  In my case, it is when the field value of 'job' changes

		$('.job').change(jobDesc);

This should get you started in the right direction, obviously your situation is different from mine, so feel free to reach out with any additional questions.  barkern@protrans.com

Thanks,

Nate

1 0
replied on April 23, 2018

Hi Nate

This is great, I will reach out if I have any questions

Thank you 

Steve

1 0
replied on April 23, 2018

Worked as advertised. Thanks Nate

0 0

Replies

replied on September 24, 2015 Show version history

Hi Nate,

Rather than using the appendTo() function it might be easier to just use the 'add' symbol. For example:

var link = "<<yourURL>>?startid="  + doc_id;

This will give a variable containing the link you require.

You can then pass this link into a field using $("#Field34").val(link);

Hope you get this sorted!

Dan

1 0
replied on September 24, 2015 Show version history

Dan,

That is working GREAT!  Thanks for all your help.  Last request that I know how to do, but for whatever reason, I cannot get it to work!  Because this will be on a form the user is filling out, I would like the link to open in a new tab without the user having to click CTRL.  I know the HTML to do this is target="_blank" but I've tried adding this in my script and cannot get it to act correctly... In fact, it breaks my entire script.  Below is the script.  

$(document).ready(function(){
$('#Field27').blur(function(){  //This is the Position Applying For field because this will trigger the 'Job Description Input field to change
    

  var doc_id = $('#q35 input').val() ; //This is the Job Description Input that changes with the Position Applying For
  var open = '&openfile="true"';
  var target = 'target="_blank"';//Add this in to get link to open in new tab
  var openLink = doc_id + open; 
  var link = "<a " + target + "href='http://servernamel/weblink8/docview.aspx?dbid=db&id=" + openLink +"'>Job Description</a>";
  document.getElementById("q34").innerHTML = link;

});
  })

Note: I updated it to open the file automatically without the user having to click it and that is why I'm using the openLink var.  

EDIT: I was able to get this working by adding a var target and inserting it before the href"..." 

Thanks again for all your help!

1 0
replied on September 24, 2015

No worries Nate, looks like a pretty slick script!

0 0
replied on September 24, 2015

Thanks Dan, I think that logic will work if I'm passing it to a field input.  If I want this to appear in a custom HTML field, what would be the HTML I enter into Field34?

Right now I just have <a href="+link+">Job Description</a>

What can I do to make this link update?

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.