I have a form that has two columns of numbers.
this form is the second form in the series of forms and can have different number of rows (selected by user in the previous form) therefore I name the textboxes with an array (for example COLA, COLA)
I am trying to add a button that adds up the numbers users enter.It does not work. What am I doing worng?
Here is my code:
var SUMA = 0;
var SUMB = 0;
var SA = parseFloat(form.COLA.value) + parseFloat(form.COLA.value);
var SB = parseFloat(form.COLB.value) + parseFloat(form.COLB.value);
form.SUMA.value = SA;
form.SUMB.value = SB;
I'm not sure if this is your whole code or not, but I'm going to guess that you just pasted parts of it.
I believe that the error is related to the names of the text boxes. If you remove the brackets, the code will work. (COL1 instead of COL)
If you are dynamically naming the text boxes from an array, leave out the brackets in the naming processing.
Each input name would look like: col0, col1, col2, col3, etc.
If the selection of how many boxes is not on the same page, you would need to save the value of boxes that the user picked either in a session variable that you could access, as a parameter in your URL string, or as a value in a hidden input field.
Thank you very much for trynig to help a beginner Compbrat but my problem is not getting solved.
Let me explain:
page 1: on this php page users tells you how many items he picks up (say 5) and click on a button page 2: on this php page an array of 5 drop down menus are created for products and for each one there is one text box for quantity. Then the user click on a button page 3: on this page information is saved to database.
I need a calculation on step 2 to add up the values entered in those texboxes of price and show the user on the same page how much it costs before he clicks the order to next step.
If I do not use array what elese can I do (becasue I would not be able to send and and use the data to the third page? and if I do use array for naming the txtboxes how do I caluclate?
This is my problem.
Any suggestions is appreciated.