# Using client-side javascript in the Racket webserver?

**URL:** <https://racket.discourse.group/t/using-client-side-javascript-in-the-racket-webserver/2292>\
**Category:** Questions & Answers\
**Created:** [September 6, 2023, 10:47pm UTC](https://racket.discourse.group/t/using-client-side-javascript-in-the-racket-webserver/2292 "2023-09-06T22:47:48Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [September 6, 2023, 11:15pm UTC](https://racket.discourse.group/t/using-client-side-javascript-in-the-racket-webserver/2292/2 "2023-09-06T23:15:27Z")

</div>

How are you generating responses generally?

With xexprs, you can embed JS in attributes by just making a string, such as

```scheme
(input ([class "player-initiative-input"]
        [type "text"]
        [inputmode "numeric"]
        [value ,(~a (player-initiative p))]
        [oninput
         "for (element of
document.querySelectorAll(\".player-initiative-input\")) { if (element
!== this) { element.disabled = true; } }"]))

```

I think you can also embed `cdata` structs via `make-cdata` in an  
xexpr that is translated by `response/xexpr` and friends as "just the  
string I meant, no translations."

But I find it convenient to serve the JS as a static file and then  
include the right metadata via a script tag. Search for "static" in  
[https://github.com/benknoble/frosthaven-manager/blob/main/server.rkt](https://github.com/benknoble/frosthaven-manager/blob/main/server.rkt).

---

_[View the full topic](https://racket.discourse.group/t/using-client-side-javascript-in-the-racket-webserver/2292)._
