Hi again Paul,
I finally gave a try to the last piece of code you wrote, the one synthesizing the long repetitve chunk I wrote myself in the first place:
Code:
//checkboxes
var total_check = 0,
checkboxes = ['quien', 'donde', 'fotos', 'comerce', 'gestion', 'noticias', 'fbook', 'tweeter'],
i;
for (i = 0; i < checkboxes.length; i += 1) {
if (document.getElementById(checkboxes[i]).checked) {
total_check = precio_check;
}
}
This works and it definetely shortens things up, but it doesn´t really do what I was needing. The idea was adding 400 (euros in this case) to 'total' variable, each time a checkbox is selected. That is, 400 per checkbox selected. And substracting 400 if any of the selected checkboxes is deselected. That is, subtracting 400 per checkbox deselected. The code you wrote equals 'total_check' to 'precio_check' (being this last one a fixed constant value of 400) if there is a checkbox selection, no matter how many checkboxes are selected. If the user ticks on either 1 or 4 checkboxes, for instance, the same value will be added to 'total' variable: 400 only. It doesn't multiply 400 by the number of checkboxes selected.
I'm not sure if there is an easy way to get that through this shortened code way you wrote...
Thanks again in advance.
Bookmarks