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 Link to comment https://forums.phpfreaks.com/topic/296215-update-form-input-field/ Share on other sites More sharing options...
maxxd Posted May 11, 2015 Share Posted May 11, 2015 Try changing divobj.innerHTML = PremAmount.toFixed(2); to divobj.value = PremAmount.toFixed(2); Link to comment https://forums.phpfreaks.com/topic/296215-update-form-input-field/#findComment-1511455 Share on other sites More sharing options...
BinaryBridge Posted May 12, 2015 Author Share Posted May 12, 2015 Worked like a dream Cheers Maxxd Link to comment https://forums.phpfreaks.com/topic/296215-update-form-input-field/#findComment-1511516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.