This is my code:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething(' + url + ')'
});
And the doSomething method:
function doSomething(url) {
windowMy = dhxWins.createWindow("externalLink", 10, 10, 630, 630);
windowMy.setText("Title");
windowMy.attachURL(url);
}
When doSomething is called, I get the error: Uncaught SyntaxError: Unexpected token :, when url="http://somewebsite/site".
What should I do? How can I pass url as parameter in JS function?
This is my code:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething(' + url + ')'
});
And the doSomething method:
function doSomething(url) {
windowMy = dhxWins.createWindow("externalLink", 10, 10, 630, 630);
windowMy.setText("Title");
windowMy.attachURL(url);
}
When doSomething is called, I get the error: Uncaught SyntaxError: Unexpected token :, when url="http://somewebsite/site".
What should I do? How can I pass url as parameter in JS function?
Share Improve this question asked Sep 18, 2013 at 13:49 petko_stankoskipetko_stankoski 10.7k42 gold badges134 silver badges234 bronze badges 2-
2
The string you create is something like
something(http://...)
which is not a valid JavaScript function call. The argument has to be put in quotes to be interpreted as string literal. – Felix Kling Commented Sep 18, 2013 at 13:51 - 1 That is not jQuery, I have no idea what that is. – OneOfOne Commented Sep 18, 2013 at 13:51
1 Answer
Reset to default 7I think you just need some extra quotes around your url:
var url = f.href.value;
ed.dom.setAttribs(e, {
href : 'javascript:void(0)',
onclick: 'doSomething("' + url + '")'
});
Otherwise, the function ends up like this:
doSomething(http://www.google.);
Instead of:
doSomething("http://www.google.");