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

Question

Question

Trying to pass a variable into hyperlink

asked on February 23, 2016

I'm trying to pass a variable from a single line field to a custom html hyperlink. My code currently is as follows: 

$(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 are the two fields I'm working with:

currently, the hyperlink is  http://www.wherever.com?startid=. I am not sure why the input from the single line is not passing into the hyperlink. I've been looking at this post for help, but have just reached a point where I'm not sure how to move forward.

 

Thanks

2 0

Answer

SELECTED ANSWER
replied on February 23, 2016

Your javascript is running as soon as the page is ready so that's why it's setting the num variable to an empty string. You'd need to change the code so that the variable is set to the value that the user enters into the single line field. Using the code example from the Answers thread you referenced, try the following:

$(document).ready(function () {

  $('#Field8').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;
  });

});
4 0
replied on February 23, 2016 Show version history

Thanks! That solved it on my test form. For some reason though, it isn't working on the actual form I need it.

I know this isn't secure, but I'm using this: 

http://answers.laserfiche.com/questions/92507/Password-to-view-a-form#92515 

as a type of password lock for the form. I'm not sure why, but the hyperlink is not being created at all on this form and I'm guessing it has something to do with this. Any thoughts?

 

edit: Never mind - it's working now. Thanks for the help!

0 0

Replies

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

Sign in to reply to this post.