You are not logged in.

1

Friday, May 21st 2021, 9:29pm

no luck in passing string with commas to javascript action

Hello, I'm using this example to pass text to a javascript function that renders it into a container layer and adds scrollbars when needed. Within my action, I use this:

Source code

1
txtadd(layer[get(layername)].onloaded, 'add_html_text(', get(textcontent2),')');


and pass to javascript action here:

Source code

1
<action name="add_html_text" type="Javascript"><![CDATA[	console.log('hello!', args[1]);


But the log only shows the text before the first comma. I've scoured the forum and have tried many different things, using quotes around the parameter, using set instead of txtadd, and various other methods. What am I doing wrong?

2

Saturday, May 22nd 2021, 12:29am

add quotes ?
txtadd(layer[get(layername)].onloaded, 'add_html_text("', get(textcontent2),'")');

3

Sunday, May 23rd 2021, 4:47pm

add quotes ?
txtadd(layer[get(layername)].onloaded, 'add_html_text("', get(textcontent2),'")');
that works beautifully - thank you @indexofrefraction!! I had tried adding quotes before but must have not had them in the right place, this was very confusing! thank you again!

4

Sunday, May 23rd 2021, 5:13pm

if your string is "a,b,c"
and you set onloaded without quotes, then you'll get

add_html_text(a,b,c);
so there are 3 arguments

instead you need
add_html_text("a,b,c");

*smile*

5

Monday, May 24th 2021, 10:36pm

yes, I think my issue was where to put the double quotes. I was adding it after the single quote and did not realize it had to be inside the single quotes. anyway, i understand the syntax now - thanks again for your help!