2

I've been through the documentation for web-servers and can't find anything on it.

Here's my code for a basic web application:

#lang racket

(require web-server/servlet
         web-server/servlet-env)

(define test '())

(define (start request)
  (define bindings (request-bindings request))
  (cond
    ((exists-binding? `cb1 bindings)
     (set! test '(1 2 3))
     (printf "~a" "(test) has been set to '(1 2 3)!")))
  (response/xexpr
   `(html
     (head (title "My Blog"))
     (body
      (h1 "Under construction")
      (form ,`(input ((name "cb1") (type "checkbox")) (value " Checkbox 1")) 
            (p (input ((type "submit") (value "Submit")))))))))

(serve/servlet start)

I want to be able to submit without having to press submit and instead by pressing a key such as enter. Is it possible to do this?

j.doe
  • 1,214
  • 2
  • 12
  • 28

1 Answers1

3

The Racket servlet produces a web page (in html) that is sent to the client. On the client the web page is shown in the user's browser. When the user press a key the browser needs to handle it. The only way to get the browser to do anything special on a key press is to use write a handler in JavaScript. Note that the Racket portion of your program only runs on the server.

In short: You need to write a small piece of JavaScript and embed it in the html page.

See How to submit form on keypress? for more information on how to do this in JavaScript.

Community
  • 1
  • 1
soegaard
  • 30,661
  • 4
  • 57
  • 106