Own Javascript does not return a value

Paginator

Client
Регистрация
30.09.2012
Сообщения
7
Благодарностей
0
Баллы
0
Hello,

I got the following code running in Zenno 4.2.5.0 which does not return a value.


Код:
var url = {-Variable.LinkItem-};
var regex = /^http/;
if(!regex.test(url)) {
	return "http://example.com" + url;
} else {
	return url;
}
Even if I try this, nothing returns:

Код:
return "http://someurl.any";
I also assigned the return value to a variable via "Put result to variable".

What is wrong with the code, or its a bug?


Greetings

Paginator
 

Paginator

Client
Регистрация
30.09.2012
Сообщения
7
Благодарностей
0
Баллы
0
I investigated that return does not work. Although it is described in the documentation of Zenno 3.

To get the final value you should either write return followed by the name of the variable whose value the macro executing your JavaScript code is supposed to return, or simply write this variable at the end, and the macro will return the value of the very last variable used in your JavaScript code.
Second problem is - if you use a {-foo-} variable to assign another variable.
If you do that, the script does not work. In my case it is the following statement:
var url = {-Variable.LinkItem-};
Also string concatination with a {-foo-} variable does not work (see my comment below)

But how can I solve my problem above without assigments?

var result = 'narf';
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
//This is also not possible - but why?
result = "http://example.de" + {-Variable.LinkItem-};
} else {
// Is there another way to do this?
result = {-Variable.LinkItem-};
}
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Don't know if this will actually help or not, but have you tried declaring the variables first outside of the javascript and then bringing them in? I'm no javascript master, just thought it might help.
 

Hungry Bulldozer

Moderator
Регистрация
12.01.2011
Сообщения
3 441
Благодарностей
834
Баллы
113
If you want to return value of var x; then just write x; at the end of JS.
To set string value you should put {-Variable.LinkItem-}; into double quotes, like this "{-Variable.LinkItem-}";
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
I would suggest to make zennoposter javascript tester somewhere online. To give access to everyone... Because i have hard time to make javascript working. I hire freelancer, but the only way i found was to give him my zenno licence to test javascript...
 

morpheus93

Client
Регистрация
25.01.2012
Сообщения
1 058
Благодарностей
244
Баллы
63

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113

Paginator

Client
Регистрация
30.09.2012
Сообщения
7
Благодарностей
0
Баллы
0
I tried everthing posted - no results :(
Even with:
Код:
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
	 {-Variable.result-} = http://example.de" + "{-Variable.LinkItem-}";
} else {
	{-Variable.result-} =  "{-Variable.LinkItem-}";
}
{-Variable.result-};
 

Paginator

Client
Регистрация
30.09.2012
Сообщения
7
Благодарностей
0
Баллы
0
-- deleted same post occured two times --
 

Paginator

Client
Регистрация
30.09.2012
Сообщения
7
Благодарностей
0
Баллы
0
*bump*

What are the differences between normal Javascript and "Zennoposter-Javascript"?

Can not get my code running...
 

hookpilot

Новичок
Регистрация
24.09.2012
Сообщения
7
Благодарностей
0
Баллы
0
Hi Paginator, check the starting double quote in line 3.

Also, did you tried what Hungry Bulldozer suggested about enclosing the variable with " "? -> "{-Variable.result-}";

I tried everthing posted - no results :(
Even with:
Код:
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
	 {-Variable.result-} = [B]"[/B]http://example.de" + "{-Variable.LinkItem-}"; 
                               [B]^missing double quote[/B]
} else {
	{-Variable.result-} =  "{-Variable.LinkItem-}";
}
{-Variable.result-};
 

Кто просматривает тему: (Всего: 2, Пользователи: 0, Гости: 2)