From c53470daa7b350ac8545d8934cedbcb1aae49bd0 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 21 May 2009 10:34:56 -0400 Subject: ccheckbox --- lib/js/urweb.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lib/js/urweb.js') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 25ed2f7a..c031678a 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -295,12 +295,12 @@ function dyn(s) { populate(x); } -function input(t, s) { +function input(t, s, recreate) { var x = document.createElement(t); x.dead = false; x.signal = ss(s); x.sources = null; - x.recreate = function(v) { if (x.value != v) x.value = v; }; + x.recreate = recreate(x); populate(x); addNode(x); @@ -308,7 +308,7 @@ function input(t, s) { } function inp(s) { - var x = input("input", s); + var x = input("input", s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); x.value = s.data; x.onkeyup = function() { sv(s, x.value) }; @@ -316,7 +316,7 @@ function inp(s) { } function sel(s, content) { - var x = input("select", s); + var x = input("select", s, function(x) { return function(v) { if (x.value != v) x.value = v; }; }); x.innerHTML = content; x.value = s.data; x.onchange = function() { sv(s, x.value) }; @@ -324,6 +324,15 @@ function sel(s, content) { return x; } +function chk(s) { + var x = input("input", s, function(x) { return function(v) { if (x.checked != v) x.checked = v; }; }); + x.type = "checkbox"; + x.checked = s.data; + x.onchange = function() { sv(s, x.checked) }; + + return x; +} + function addOnChange(x, f) { var old = x.onchange; x.onchange = function() { old(); f (); }; -- cgit v1.2.3