newphpcoder Posted October 17, 2011 Share Posted October 17, 2011 Hi!I used javascript for my autocalculate and it works and now my problem is how can I SUM the total from autocalculate and the Data from other textbox.here is my code: function autocalearn(oText){if (isNaN(oText.value)) //filter input{alert('Numbers only!');oText.value = '';}var field, val, oForm = oText.form, TotEarn = a = 0;for (a; a < arguments.length; ++a) //loop through text elements{field = arguments[a];val = parseFloat(field.value); //get valueif (!isNaN(val)) //number?{TotEarn += val; //accumulate}}oForm.TotEarn.value = TotEarn.toFixed(2); //out}</script> The scenario is I have a Amount textbox and it has a value from database. And I have textboxes which is autocalculate and the total of that is display in total earn and now i want that the total earn and total amount will SUm and display in total earn.. <input name= "Amount" class = "LFieldTot" type="text" maxlength="12" tabindex="0" size="12" value="{$Amount}" readonly="readonly"/> Thank you...I tried to put {Amount} in Total Earn Values but when I insert data in the earnings textbox the data was the calculate from the textboxes, it did not sum the Amount. Link to comment Share on other sites More sharing options...
Ingolme Posted October 17, 2011 Share Posted October 17, 2011 You can print a PHP variable right into your script. var amount = <?php echo $Amount; ?> Or if your script is using data from a form, access the form element: var amount = document.getElementById("amount").value; <input type="text" id="amount"> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.