I am currently exploring the most effective way to update a database value based on the input from a textbox. The database contains two columns: "Amount Added" and "Money". The value in the "Money" column depends on the "Amount Added" value.
My goal is to automatically update the textbox for "Money" once the "Amount Added" value has been changed, or have the controller calculate and input the value upon clicking submit.
I attempted to achieve this using JavaScript, although it is not my expertise. I found a code snippet in another post here:
$(document).ready(function Update() {
var one = document.getElementById('AmountAdded'),
two = document.getElementById('Money');
two.value = parseInt(one.value) * 2 / 100;
})
Unfortunately, this approach did not work as expected. Should I continue with this method and refine it, or consider implementing it through the controller?
If relevant, I am utilizing Entity Framework for this project.
UPDATE: After realizing that the JavaScript was located within the body due to being in the view, I moved it to the layout page. Additionally, following Dhaval's advice, I corrected "GetElementById" to "getElementById".
Initially, the first reload displayed the "Money" value as NaN. To address this, I set the default value to 0. However, changing it subsequently does not reflect the updated value in Html.EditorFor.
Any suggestions or insights would be greatly appreciated.