I'm writing a webserver app in clojure with Hiccup (and other things). I'm trying to have a check-box enable and disable two drop-down fields with a little JS but I can't make it work.
[:head
[:script "function toggleText(cb, t1, t2) {
document.getElementById(t1).disabled = !cb.checked;
document.getElementById(t2).disabled = !cb.checked;
}"]]
[:td (hf/check-box {:on-change (str "toggleText(" (name endtag) "," (name tytag) "," (name tmtag) ")")} endtag)]
[:td (hf/drop-down tytag (range 2013 2031) 2017)]
[:td (hf/drop-down tmtag (range 1 13) 6)]
on-change
is a React handler and won't work in server-side HTML.
If you don't want to create a separate JS file, you can use the onclick
attribute: the below should work (provided that the hf/check-box
function creates an element with the given properties):
[:td (hf/check-box
{:onclick (str "toggleText(" (name endtag) ","
(name tytag) "," (name tmtag) ")")}
endtag)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With