In the index.ejs page, we will have an input field with the ID nickName when it is rendered. We can simply read the value by writing the following lines of code:
val nickName = (document.getElementById("nickName") as? HTMLInputElement)?.value
However, to cover more possibilities, we have written it in a slightly different way. We have written it as if we are taking the input as an event.
The following code block will continuously read the value that is entered into the nickName input field:
private fun onInput(): (Event) -> Unit { return { val input = it.currentTarget as HTMLInputElement when (input.id) { "nickName" -> nickName = input.value "emailId" -> email = input.value } } }
Check out, we have used the when function, ...