Thank you for your help again.
## Set the cursor of a 'textarea' to a position given in an 'input' field
# From javascript
proc setSelectionRange(elem: Element; selectionStart, selectionEnd: int)
{.importjs: "#.setSelectionRange(#, #)".}
# For 'onkeyupenter = setCursorToPositionInTextarea' at
# 'input' for the position of the cursor
proc setCursorToPositionInTextarea(ev: Event, n: VNode) =
let pos = n.value.parseInt
let element = getElementById(kstring("textareaId"))
element.focus() # necessary
element.setSelectionRange(pos, pos)
## Simulate 'type=number" for a textarea
# 'onkeydown = onkeydownDigitsOnly' at textarea
proc onkeydownDigitsOnly(ev: Event; n: VNode) =
# Digits only, but editable
let keyCode = (ev.KeyboardEvent).keyCode
if (ev.KeyboardEvent).key == kstring("Alphanumeric") and (keyCode < 48 or
keyCode > 58):
# it is not a digit key
ev.preventDefault()
Run