Javascript to select which page to go to

T

timothy.pollard

Hi

I have a questionnaire I need to put on a web page which needs a simple
javascript to help process it. The questionnaire has 4 columns of 10
Qs, each Q with its checkbox to tick if it applies. Each column
measures a different aspect of personality. What I need to do is create
a routine which calculates the number of checkboxes checked in each
column so I'll end up with 4 numbers. So I need to increment each
column's total by one when each check box is checked and reduce it by
one each time a checked box is unchecked (ie. if the user changes their
mind).

I'm not a javascripter, so please could someone point me in the right
direction!

Thanks in advance for any help.

Tim P
 
T

timothy.pollard

Actually don't worry, cracked it:

<script language="JavaScript" type="text/JavaScript">
<!--
function calculate() {
var elems = document.forms['form1'].elements;
var total = 0;
for(var i=0;i<elems.length;i++) {
if (elems.checked) {total += +(elems.value);}
}
elems['Col1Tot'].value = total;
}
//-->
</script>


This works for all elements in form1 and sums to text box Col1Tot

Repeat for each form separately, works OK. Probably not the best way to
do it, but works ok for me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,156
Messages
2,570,877
Members
47,401
Latest member
CliffGrime

Latest Threads

Top