Dropdown list "last item attribute value" selector ?

gcomm

Client
Регистрация
01.03.2011
Сообщения
332
Благодарностей
93
Баллы
28
Hello ZP crew,

I have encountered a simple drop down with various "location_names".

I must select the last item on the drop down menu. The problem however is returning visit to the pages has new values within that drop down. Sometimes 2 sometimes 13 items...

How to select the last item in the dropdown each time ?


*** TIP *** the last field in the drop down is always named "outside" if that helps... when I push "O-U-T" for example this brings to the final field, however when I set the value as "OUT" this does not work....

Any help would be cool. Thanks.
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
you need to use full value to set - not partial.
Or you can read number of items (length property), and select last one by number.
 

gcomm

Client
Регистрация
01.03.2011
Сообщения
332
Благодарностей
93
Баллы
28
The following zenno script....
Код:
{-JS.Execute-|-var x=document.forms[0].test.length;-}
Fails to return anything from the following form...
Код:
<form>
<select name="test">
<option>blah</option>
<option>blah</option>
<option>blah</option>
</select>
</form>

We have also tried ..
Код:
{-JS.Execute-|-document.forms[0].test.length;-}
The following code works from within the HTML page itself, but still Zenno returns no results from any of the examples tried above. So we know this is proper javascript for accessing the element inside the DOM.
Код:
alert(document.forms[0].test.length);
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
Perhaps zenno JS isn't executed in the DOM context, but as separated script (Javascript doesn't need to be tied to the browser) - don't know didn't tested that as it wasn't needed to me.
You can get length as html element (from branch builder instead of setting you can also get some value) - I do that by myself.
 

gcomm

Client
Регистрация
01.03.2011
Сообщения
332
Благодарностей
93
Баллы
28
do you mean like this ?
Код:
{-JS.PrepString-|-{-JS.Execute-|-var x=document.forms[0].test.length;-}-}
Aka... put the Execute statement (which returns nothing), inside the "Prepare" statement, which just spits out the text
{-JS.PrepString-|-THAT IS HERE-}

With regards to the following
You can get length as html element (from branch builder instead of setting you can also get some value) - I do that by myself.
The html element length is dynamic and so on each zenno thread it may vary from between 1 element and 99 elements. Using this method would set the element as a static length.
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
1. I mean it's possible that the DOM of the page isn't accessible at all via javascript executed within zenno.

2. You don't undertand. It will read the value, everytime template is executed so if current select has 20 elements you will get returned value 20, if select has 10 elements you get value 10.
 

gcomm

Client
Регистрация
01.03.2011
Сообщения
332
Благодарностей
93
Баллы
28
gemini,

Thanks for the help. Reading from the DOM using the branchbuilder did work --- sort of.

Steps to reproduce this functionality:
1. Use the branch builder to get the element.
2. No length option, so choose Get/Anything --- we selected "value"
3. Once inside the Project Maker, go to the tree for that element, and change the "Attribute Name" under "Taking A Value" from "value" to "length"

This seems to allow the functionality.

ADMINS -- Please add "length" to the Branch Builder.

Thanks.
 

gemini

Client
Регистрация
10.03.2011
Сообщения
160
Благодарностей
31
Баллы
28
there is no selectable option, but you might enter it manually in the branch builder also :-)
 

Tropicalista

Client
Регистрация
24.05.2011
Сообщения
29
Благодарностей
0
Баллы
0
please could you explain more?

If I have a select and want select an option by javascript how should I do?

my select is named "realitems" for example, and I would choose a value with javascript

Код:
	sl = document.getElementById('realitems');
		for (var j=0;j<sl.length;j++) {
                      sl.selectedIndex = j;
		}
How to execute this in a template with javascript?
 

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