views:

22

answers:

2

I have a form that have input element and the select element with multi select. so how can I set value for the input element and select element in mootools.

A: 

For dropdown:

$('idOfSelect').selectedIndex = x;

For text:

 $('IdOfInput').value = 'Foo';
ryber
is there any other way to do this. like in jQuery('#idOfSelect').val([2,4]) or jQuery('#idOfInput').val('Foo')
YuanChen
about the select element I only know an array of value of the select element. how can I turn it into selectedIndex
YuanChen
+1  A: 

basically - element.get("value"); returns the value for all inputs, selects and textareas, .set("value", value); to set them (except for multiples)

it's more complicated for select with multiple - the above returns the FIRST selected only, you need to do element.getSelected().get("value") to recieve an array of values (.getSelected() on its own will return the pointers to the actual option elements)

and finally, to set multiple selections, only way i can think of atm is to write your own element prototype that walks through child nodes with the values as specified and does .set("selected", "selected")

let me know if you need any help writing the latter

Dimitar Christoff