Search code examples
ocamljs-of-ocaml

How to trigger and handle a click event?


In the following code, I try to handle a click event on a checkbox. I expect to see the word "hello" printed in the javascript console, but instead I see nothing. How can I modify the code to get the print statement to execute?

 let checkGroupByRounds = Dom_html.createInput ~_type:(Js.string "checkbox") doc in
  Lwt_js_events.clicks checkGroupByRounds (fun event event_loop ->
    Lwt.return (Printf.printf "hello"));
  Dom.appendChild container checkGroupByRounds;

Solution

  • You need to flush the standard output with a new line Printf.printf "hello\n" or an explicit flush flush stdout.