In comp.lang.javascript message <ptsjf417lo2sceejf8m19perf9dreu8bfm (AT) 4ax (DOT)
com>, Sat, 18 Oct 2008 16:40:54, test (AT) testnospam (DOT) nl posted:
Quote:
I have 8 sets of radiobuttons, each has a on and off state.
When this form is send, I would like that the state of the buttons is
converted to a byte.
Can I do this easily? |
Apparently not. But I can : consider
<form> DEMO ONLY; lacks polish
<br>..0..1
<br><input type=radio name=x1><input type=radio name=x1> 1
<br><input type=radio name=x2><input type=radio name=x2> 2
<br><input type=radio name=x3><input type=radio name=x3> 4
<br><input type=radio name=x4><input type=radio name=x4> 8
<br><input type=radio name=x5><input type=radio name=x5> 16
<br><input type=radio name=x6><input type=radio name=x6> 32
<br><input type=radio name=x7><input type=radio name=x7> 64
<br><input type=radio name=x8><input type=radio name=x8> 128
<br> <input type=button value="?" onClick="Wot(this.form)">
<script>
function Wot(F) { var X=0, J=9
while (--J) X = X*2 + F["x"+J][1].checked
alert(X) }
</script>
There, F["x"+J] refers to a radiobutton pair.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.