Giampablo
07-16-2009, 03:54 PM
I have two tables, as follows:
TABLE A
Question 1 Opt1 Opt2 Opt3 Opt 4 Opt5
Question 2 Opt1 Opt2 Opt3 Opt 4 Opt5
....
Question n Opt1 Opt2 Opt3 Opt 4 Opt5 TOTAL A
same as above for TABLE B.
I am using this function:function Somma() {
var sum = 0;
var qn, elem;
for (i=0; i<65; i++) {
qn = 'qn'+i;
elem = document.getElementById(qn);
if (elem.checked == true) { sum += Number(elem.value);
}
}
document.getElementById('totaleA').value = sum;and another function SommaB() for TABLE B, with few changes needed.
What I get is two autocalculated and populated fields, totaleA and totaleB. Really I do not need to show the totals.
Since each total can be a positive or negative number I just need a comparison between the two values, with four possible results (++, +-. --, -+).
An user, after answering all questions, should be able to click a button and get his own profile (out of 4 profiles) displayed in a new page.
Maybe this is very basic but I have not been able to find an example code of how to do above, also I am just a newbie in javascript and i do not know how to build a function.
Thanks in advance, and excuse me for my bad (very italian) english.
TABLE A
Question 1 Opt1 Opt2 Opt3 Opt 4 Opt5
Question 2 Opt1 Opt2 Opt3 Opt 4 Opt5
....
Question n Opt1 Opt2 Opt3 Opt 4 Opt5 TOTAL A
same as above for TABLE B.
I am using this function:function Somma() {
var sum = 0;
var qn, elem;
for (i=0; i<65; i++) {
qn = 'qn'+i;
elem = document.getElementById(qn);
if (elem.checked == true) { sum += Number(elem.value);
}
}
document.getElementById('totaleA').value = sum;and another function SommaB() for TABLE B, with few changes needed.
What I get is two autocalculated and populated fields, totaleA and totaleB. Really I do not need to show the totals.
Since each total can be a positive or negative number I just need a comparison between the two values, with four possible results (++, +-. --, -+).
An user, after answering all questions, should be able to click a button and get his own profile (out of 4 profiles) displayed in a new page.
Maybe this is very basic but I have not been able to find an example code of how to do above, also I am just a newbie in javascript and i do not know how to build a function.
Thanks in advance, and excuse me for my bad (very italian) english.