Passed URL string not interpret as a string

I read quite some articles and tried some approaches, but couldn't get it to work.

htmlCode += '<button id="' + addButtonId + '" title="' + addButtonTitle + '" class="button" onclick="getProductUrl(' + url + '); return false;"><span><span>' + addWithButonTitle + '</span></span></button>';

and the function itself:

getProductUrl: function(url) {
        return setLocation('\'' + decodeURIComponent(url) + document.getElementById('qty_field').value + '\'');

Apparently, the string value of the url is not treated as a string. I get an error of missing bracket here: getProductUrl(http:^// of the url. Of course the problem is not in the bracket, but in the fact that the // are treated as a start of a comment.

So the thing that I have to do is to pass this url string value CORRECTLY as a string. I tried first decoding and then passing (because decodeURIComponent(url) should return string. Also I tried String(url) and url + "". Also somehow escaping the special characters: url.replace('/','\/') or even the /g thingy, which didn't work at all.

So, all these approaches were unsuccessful. I would really appreciate a hint or a solution here.


Try this one

onclick="getProductUrl('" + url + "');"

For your updated line of code:

htmlCode += '<button id="' + addButtonId + '" title="' + addButtonTitle + '" class="button" onclick="getProductUrl(\'' + url + '\'); return false;"><span><span>' + addWithButonTitle + '</span></span></button>';

Need Your Help

Making Instances Of All Classes That Extend A Superclass In Java

java class reflection

When I run my project on Netbeans, its fine, but when I build the Jar, it just wont work. No exceptions, it just wont scan the files. I'm trying to make new instances of all of the classes that ext... mvc master details and routing

c# routes

I'm trying to model class and sections of a class and further instances of sections.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.