Gendaful
Gendaful

Reputation: 5802

How to pass a value of java script variable in the rel attribute of anchor

This is a very basic and silly question but i am facing this problem since a long and now it has confused me :(

I am trying to pass a javascript variable value as a querystring parameter in the rel attribute of the anchor tag. But some how I am not able to pass the value.

Here is my code.

this.pid = pid;
console.log('here is pid'+this.pid); // I am getting correct value here.
var formattedUrl = "<a rel=EProgramDetail?programid='+pid+'&format=SD>" +  value + "</a>" ;

but onclicking of the url, it gives me an error but if i hardcode the value, it runs fine.

Please help.

Regards Hp

Upvotes: 0

Views: 680

Answers (2)

lonesomeday
lonesomeday

Reputation: 237895

As the syntax highlighting demonstrates, you're mixing up your quotes:

var formattedUrl = "<a rel=EProgramDetail?programid=" + pid + "&format=SD>" +  value + "</a>" ;

Since you started the string with double quotes, you need to end it with double quotes. Single quotes will be treated as a literal single quote, part of the string.

Upvotes: 4

Timothy S. Van Haren
Timothy S. Van Haren

Reputation: 8966

Your single and double quotes aren't matching up.

Try this:

var formattedUrl = "<a rel='EProgramDetail?programid=" + pid + "&format=SD'>" +  value + "</a>" ;

Upvotes: 3

Related Questions