js.nim 572 B

12345678910111213141516171819202122232425
  1. discard """
  2. cmd: "nim js --hints:on $options $file"
  3. """
  4. # This file tests the JavaScript generator
  5. import
  6. dom, strutils
  7. # We need to declare the used elements here. This is annoying but
  8. # prevents any kind of typo:
  9. var
  10. inputElement {.importc: "document.form1.input1", nodecl.}: ref TElement
  11. proc OnButtonClick() {.exportc.} =
  12. let v = $inputElement.value
  13. if v.allCharsInSet(whiteSpace):
  14. echo "only whitespace, hu?"
  15. else:
  16. var x = parseInt(v)
  17. echo x*x
  18. proc OnLoad() {.exportc.} =
  19. echo "Welcome! Please take your time to fill in this formular!"