Is there a way to read an input value as in JavaScript using java - elemental2? My entire code looks like this:
public void onModuleLoad() {
document.body.style.margin = MarginUnionType.of("0");
document.body.appendChild(navigation());
document.body.appendChild(mainSection());
}
// *********************** //
// Elemental methods
public static HTMLElement mainSection() {
// create list
HTMLElement ul = (HTMLElement) document.createElement("ul");
ul.style.listStyle = "none";
HTMLElement li = (HTMLElement) document.createElement("li");
li.textContent = "Tasks";
ul.appendChild(li);
return ul;
}
public static HTMLElement navigation() {
// create button
HTMLButtonElement button = (HTMLButtonElement) document.createElement("button");
button.textContent = "Add Task";
button.addEventListener("click", evt -> onAddTask());
// create main nav
HTMLElement mainNav = (HTMLElement) document.createElement("nav");
mainNav.className = "main-nav";
mainNav.appendChild(addInput());
mainNav.appendChild(button);
return mainNav;
}
public static HTMLInputElement addInput() {
// create input
HTMLInputElement input = (HTMLInputElement) document.createElement("input");
input.placeholder = "Enter your name here";
input.id = "tasks-input";
return input;
};
public static void onAddTask() {
alert(document.getElementById("tasks-input").getAttribute("value"));
}
}
Basically when I click on the button I want to print whatever I typed into the input. Thanks!