Hi, I’m not a JavaScript coder; I generated the code using an AI coding tool.
I'm trying to use JavaScript on Forms 10 version to retrieve a value from field-1 and display a calculated result in field-2 with currency formatting and additional text.
Example:
If field-1 contains $50,000, then field-2 should display:
"Changed less than $45,000 or more than $55,000."
However, my current code isn't working as expected. Any help or suggestions would be greatly appreciated!
/*-------------------------------------------------------------*/ // Estimated Income change $(document).ready(function() { // Retrieve Prev Year income field and convert it to a number const appPrevIncomeField = document.getElementById('appHHIncome'); //const appPrevIncomeField = $(".appHHIncome input").val(); const appHHIncome = parseFloat(appPrevIncomeField.value); // Function to format numbers as US currency const formatCurrency = (value) => new Intl.NumberFormat('en-US', { style:'currency', currency:'USD' }).format(value); // Calculate income +10% and income -10% const incomeIncrease = appPrevIncome + appPrevIncome * 0.1; const incomeDecrease = appPrevIncome - appPrevIncome * 0.1; // Concatenate the result const result = `Increased Income +10%: ${formatCurrency(incomeIncrease)} |Derased Income -10%: ${formatCurrency(incomeDecrease)}`; // Set the result into the app_Estimatedincome field const estimatedIncomeField = document.getElementById('appEstimatedincome'); estimatedIncomeField.value = result; });