[js] getElementById().value compiler error

37 views
Skip to first unread message

rb1147x

unread,
Jun 28, 2016, 1:46:47 PM6/28/16
to Haxe
Hello,

I'm trying to get the value of an html input field, but using "...getElementById().value" appears to throw a compiler error.

Example code I've been using:

var test = js.Browser.document.getElementById("search-input-box").value;
js
.Browser.alert(test);

and the compiler error:

js.html.Element has no field value

I can work around this by using untyped __js__, however, ".value" should be acceptable, right?

Thanks!

Phillip Chertok

unread,
Jun 28, 2016, 2:18:15 PM6/28/16
to Haxe
The object returned by 'getElement' is of type 'Element' this class has no property called 'value'. 

Instead you should do something like:

var test:InputElement = cast js.Browser.document.getElementById("search-input-box");

if(test !=null )js.Browser.alert(test.value);

rb1147x

unread,
Jun 28, 2016, 2:31:00 PM6/28/16
to Haxe
Ah ha. Okay, thanks for the explanation!
Reply all
Reply to author
Forward
0 new messages