JRS: In article <44************ *********@news. zen.co.uk>, dated Sat, 20
May 2006 22:38:09 remote, seen in news:comp.lang. javascript, Bryan
Hepworth <bryanatredfedo ra.co.uk@?.?> posted :
Hi Everyone
I'm wondering what the best practice is for a particular task I'm trying to
accomplish. I'm using two sets of radio buttons for a user to select values
from. These values then go into a couple of tables to show some heat loss
calculations depending on the values chosen I want the tables to have the
relevant values filled in. Is the best way to accomplish this a long list of
if then else type statements or is there a better way of doing this?
The following scans a set of radiobuttons identified by Rbtn and returns
the value of the element of the array Arr corresponding to the selected
button.
function RadBtns(Rbtn, Arr) { var Q, J=0
while (Q=Rbtn[J]) { if (Q.checked) return Arr[J] ; J++ } }
The array can be supplied as a literal parameter (for a unique set of
buttons) or as a variable. The contents of the array can be of any
type, though it's likely that they will be similar.
From <URL:http://www.merlyn.demo n.co.uk/estr-bcp.htm#33>, in which the
buttons select which Easter function is to be tested (years in error, if
any, would be marked X) :-
function BCPtest(F) { var St, A, B, Y, OK, OKA = ["X", "."], E = 0
with (F) { var Y1 = GetNum(y1), Y2 = GetNum(y2),
BCPn = RadBtns(RBn, [BCPEaster1, BCPEaster2, BCPEaster3]) }
St = FuncName(BCPn) + " : X marks errors\n"
for (Y=Y1 ; Y<=Y2; Y++) { if (Y%10==0) St += "\n"
A = BCPn(Y)
B = EGREaster(Y) ; B = new Date(Date.UTC(Y , B.M-1, B.D))
OK = +A==+B ; if (!OK) E++
St += Y + OKA[+OK] + " " }
document.write( "<pre>", St, "\n Errors ", E, "<\pre>") }
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.