HighDots Forums  

Convert state of radiobutton => byte on send

Javascript JavaScript language (comp.lang.javascript)


Discuss Convert state of radiobutton => byte on send in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
test@testnospam.nl
 
Posts: n/a

Default Convert state of radiobutton => byte on send - 10-18-2008 , 10:40 AM






I have asked a sortlike question on this group, but this is an other
approach for this problem.

I want to send information about a set of 8 radiobuttons to a device
that listens to TCP/IP on port 80.

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.

So button the on state of these buttons adds the following value to
the value that is send in the GET command.
Button 1 = 1
Button 2 = 2
Button 3 = 4
Button 4 = 8
Button 5 = 16
Button 6 = 32
Button 7 = 64
Button 8 = 128

So if button 1 and 8 are marked at the time the form is send, the
script adds the values of these buttons 1 + 128 = 129 and send this as
result of the form.

Can I do this easily?



Reply With Quote
  #2  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: Convert state of radiobutton => byte on send - 10-18-2008 , 05:54 PM






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>&nbsp; <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.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.