BinaryBridge Posted May 11, 2015 Share Posted May 11, 2015 I have a form that updates a total based on the fields values entered on a form when the user leaves each field. This works fine but I also want to update one of the entry fields which is a percentage of another. I have in my js var theForm = document.forms[frm]; var eTotal = theForm.elements["Total"]; var ePremium = theForm.elements["Premium"]; if (eTotal.value > 0) { var PremAmount = parseFloat(eTotal.value * ePremium.value / 100); } var divobj = document.getElementById('PremAmount'); divobj.innerHTML = PremAmount.toFixed(2); Which is called with onblur="addPrem('totals')" The original value in the totals field from the MySQL table is 770.00 This produces the following html page <input name="PremAmount" tabindex="1" class="ent" id="PremAmount" size="2" value="77.00"> When I change the total to 888.00 I get the following <input name="PremAmount" tabindex="1" class="ent" id="PremAmount" size="2" value="77.00">88.80</input> So it looks like it's working but writing a div rather than into the field itself Can anyone help me with this please Quote Link to comment Share on other sites More sharing options...
Solution maxxd Posted May 11, 2015 Solution Share Posted May 11, 2015 Try changing divobj.innerHTML = PremAmount.toFixed(2); to divobj.value = PremAmount.toFixed(2); Quote Link to comment Share on other sites More sharing options...
BinaryBridge Posted May 12, 2015 Author Share Posted May 12, 2015 Worked like a dream Cheers Maxxd Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.