Get the value of the selected <select> element in the dart

How can I get the selected item option? document.query ("# ​​id") - returns an element that does not matter so I cannot:

var val = document.query("#id").value;

var val = (SelectElement)(document.query("#id")).value; // - "SelectElement is class and cannot be used as an expression"

how to make type conversion in darts right?

+3
source share
3 answers

just need:

String str = document.query("#idOfSelect").value;

will warn, but you can ignore it

+1
source

In general, when dealing with any HTML element, I usually request the HTML element first:

InputElement myElement = document.query(#myInputElement);

Then use some kind of event to capture the value contained in this element:

int val = Math.parseInt(myElement.value);

So, for example, in HTML, I could have an input element of a range of types:

<input id="mySlider" type="range" min="1000" max="10000" step="20" value="5000" />

In Dart, I would capture the value of this slider using the mouse up event:

InputElement mySlider = document.query('#mySlider');
mySlider.on.mouseUp.add((e) {
  int _val = Math.parseInt(mySlider.value);
  document.query('#status').innerHTML = "$_val";
});

: M1 as. HTML :

<p id="text">This is some text</p>

, :

String str = (query('#text') as ParagraphElement).text;
+4

I used:

var val = int.parse(query("#id").value, onError: (_) => 1);

This prevents an exception in case of a request ("# id"). The value is null and assigns a default value (1).

0
source

All Articles