#Get content from html input by id

1 messages · Page 1 of 1 (latest)

lucid sierra
#

Hi, I am trying to access the content of an html input field and pass the content as a string when I press "enter" or the button.

html.div(
                [attribute.class("flex gap-2 mb-6")],
                [
                  html.input(
                    [
                      attribute.type_("text"),
                      attribute.placeholder("Player name"),
                      attribute.id("player-name-input"),
                      attribute.class("input input-bordered flex-1"),
                      event.on_keyup(fn(evt) {
                        case evt {
                          "Enter" ->  AddPlayer("New Player")
                          _ -> NoOp
                        }
                      })
                    ]
                  ),
                  html.button(
                    [
                      attribute.class("btn btn-primary"),
                      event.on_click(GetPlayerNameAndAdd)
                    ],
                    [html.text("Add Player")]
                  )
                ]
              )
ebon scroll
#

Instead of getting the content by finding the DOM element. You update the content in your model as the user types.

lucid sierra
#

Okay, thank you, i will try it.