carlbrooks1995
asked on
Total number of marks is not changing
Hi,
I have a test application here which you can use: Application
Please follow steps below in order to use the app:
1: Open the application and you will see that "Total number of Marks Remaining" is 20. Click on the "Add Question" button, this will append a row underneath.
2: Now within the appended row there is a green plus button, click on this button and a modal window will appear with a search bar inside.
3: In the search bar type in 2+2 an then enter the search. A row will appear where under the "Number of Marks" column it shows the number 5. Click on the "Add" button to add the row.
4: This is where the problem is, you will see that in the appended row it says in the text input "5" but if you go back to the top it still says "Total number of Marks Remaining: 20". This should change to 15 as 20 - 5 = 15. But it does not change.
My question is that after the user has added a number into an appended row, how can I get the total marks number to change? Is it because I am using the "OnChange" attribute?
Below is a jsfiddle where it shows the whole code: (Jsfiddle is not a working example, it is just there so you can see the whole code):
http://jsfiddle.net/WZKrP/
I have a test application here which you can use: Application
Please follow steps below in order to use the app:
1: Open the application and you will see that "Total number of Marks Remaining" is 20. Click on the "Add Question" button, this will append a row underneath.
2: Now within the appended row there is a green plus button, click on this button and a modal window will appear with a search bar inside.
3: In the search bar type in 2+2 an then enter the search. A row will appear where under the "Number of Marks" column it shows the number 5. Click on the "Add" button to add the row.
4: This is where the problem is, you will see that in the appended row it says in the text input "5" but if you go back to the top it still says "Total number of Marks Remaining: 20". This should change to 15 as 20 - 5 = 15. But it does not change.
My question is that after the user has added a number into an appended row, how can I get the total marks number to change? Is it because I am using the "OnChange" attribute?
Below is a jsfiddle where it shows the whole code: (Jsfiddle is not a working example, it is just there so you can see the whole code):
http://jsfiddle.net/WZKrP/
ASKER
It is ok, I fgured it out
Just for curiosity: what was wrong...?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I do noto understand why in "calculateTotal" function, if you already declare a state variable "totalmarks" equal to 20, you need to declare first "var totalweight = totalmarks;" and then try to refresh it with "totalweight = totalweight - Number($(elm).val(), 10);"; wouldn't it be the same to set "totalweight = totalmarks - Number($(elm).val(), 10);"?