Dropdown list "last item attribute value" selector ?

  • Автор темы Автор темы gcomm
  • Дата начала Дата начала

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.
 
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.
 
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);
 
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.
 
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.
 
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.
 
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.
 
there is no selectable option, but you might enter it manually in the branch builder also :)
 
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?
 

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