dcsimg
JavaScript Checkbox Addition
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nainil_Chheda
Posted On:   Thursday, August 4, 2005 10:03 AM

Hi,

I am a newbiee in JavaScript.

I am attaching an image which will explain exactly wat I want. Firstly I have 4 rows (namely 0, 1, 2, 3). I want only 1 checkbox to be selected from amongst these at any given point of time. Once the visitor checks all the rows the rows should have an individual sum. Plus all the individual sums should be added together into the TOTAL.

How would the code look in JavaScript? Please help.

Nainil C.

Re: JavaScript Checkbox Addition

Posted By:   Almagest_FUTT  
Posted On:   Thursday, August 4, 2005 11:46 AM

A common interface paradigma states that whenever you need only one selection from multiple options, you should use radiobuttons (not checkboxes). Would have the benefit that if you used checkboxes, you'd have to handle the deselection of the other ones yourself -- whereas with radiobuttons, the browser does it for you, provided you give the mutually-exclusive buttons the same name="".

As far as i can see it, if i were you i'd assign each of the buttons a special id="", then i'd pass a function, let's say computeTotal(), to each of the boxes' eventhandler onchange="". In this function, retrieve all the boxes using document.getElementById(""), compute the total for each column (you said rows, but meant columns, didn't you?) and the overall total, then put these values in the sumfields.
About | Sitemap | Contact