MooTools - How to use getSelected ()

I am trying to learn MooTools and I ALWAYS ARE javascript noobie, so please be careful with me.

What I'm going to do is to change the state of the forbidden input field (type is text) when a specific parameter is selected. The html is a bit like tis:

<select class="wide" id="selectBox" name="option> 
  <optgroup label="Common">
      <option value="one">One<option>
      <option value="two">Two<option>
      <option value="three">Three<option>
  </optgroup>
  <optgroup label="Less Common">
      <option value="other">Other<option>
  </optgroup>
</select>
<input id="other" type="text" disabled="disabled" />

This is what I was HOPING, would give me a value that needs to be checked in the if statement, which would then change the input disabled to enabled:

window.addEvent('domready', function(){
 $$('#selectBox').addEvent('change',function(){
  var selection = $$('#selectBox').getSelected();
  alert(selection);
   });
});

When we run the code (i.e., select a different value in the selection window), all I get is that [object HTMLOptionElement].

The mootools documentation for this method is SPARSE and only says:

Element Method: getSelected

Returns the selected options, select an item.

Returns:

* (array) An array of the selected elements.

Examples: HTML

<select id="country-select" name="country">
    <option value="US">United States</option
    <option value ="IT">Italy</option>
</select>

Javascript

$('country-select').getSelected(); //Returns whatever the user selected.

Note:

, select. , .

!

-, , , . :

var selection = $$('#selectBox').getSelected().value; //and
var selection = $$('#selectBox').getSelected('value'); //and
//a WHOLE bunch of other wild ideas including
var selection = $$('#selectBox').getSelected();
alert(selection[0]);

. undefined, [object HTMLOptionElement].

+3
6

, , .

$$() - ( document.getElements(), ) - id.

document.id("idhere") $("idhere")

mootools 1.2 +

document.id('selectBox').addEvent('change',function() {
    alert(this.get("value")); // get value
    alert(this.getSelected().get("value")); // gets the option that selected and then it value
});

, - , " name=" > .

getSelected , , selectEl.get( "value" ) . ,.get( "" ) .

: http://www.jsfiddle.net/dimitar/SmShF/

:)

+14

, Mootools:

$('selectBox').getSelected().get('text')
+4

, !

​​ , :

var selection = document.getElementById("selectBox").value;
alert(selection);

.

mootools, , ( )

var selection = $('selectBox').getSelected();
alert(selection[0].value);

:

<select class="wide" id="selectBox" name="option> 

name, , id. , , , , . id="selectBox" name="selectBox

name .

<option>...<option>, <option>...</option>

+2

, , :

$('country-select').getSelected().get('value')[0];
0

, :

alert($('selectBox').value)

, :

var selectBox = document.id('selectBox');
alert(selectBox.get('value'));
0

.getSelected() . . : http://mootools.net/docs/core/Element/Element#Element:getSelected. :

var $obj=$$('#id').getSelected()[0];
alert( $obj.get('text') );
alert( $obj.get('value') );
0

Source: https://habr.com/ru/post/1756671/


All Articles