Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set value for the form element using mootools

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.

like image 314
YuanChen Avatar asked Jul 08 '10 16:07

YuanChen


2 Answers

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

like image 126
Dimitar Christoff Avatar answered Dec 04 '22 21:12

Dimitar Christoff


For dropdown:

$('idOfSelect').selectedIndex = x;

For text:

 $('IdOfInput').value = 'Foo';
like image 21
ryber Avatar answered Dec 04 '22 19:12

ryber