Kano Posted April 2, 2007 Share Posted April 2, 2007 Hi there, I need help with this javascript because it does not work as far i can tell? <SCRIPT> function gettotals(obj, rowcnt){ var stot = 0;var temp = 0;var ff = 0; for (var cnt = 1; cnt <= rowcnt; cnt++){ temp = (obj.form.getElementById("price_"+cnt).value) * (obj.form.getElementById("qty_"+cnt).value); stot += temp; } ff = stot.toFixed(2); obj.form.elements['s_total'].value = ff; } </SCRIPT> <BODY> .... <?php while(blarb){... <input type = 'text' id = 'price_$rowcnt' name = 'price_$wsi_id' value = '$wsi_price' ..... <select id = 'qty_$rowcnt' name='qty_$wsi_id' ....... .....} <input type="text" name="s_total"..... <input type='button' value = 'Get Totals' onclick='gettotals(this, \"$rowcnt\")' /> Thanks for any help.. Link to comment https://forums.phpfreaks.com/topic/45251-form-total/ Share on other sites More sharing options...
obsidian Posted April 2, 2007 Share Posted April 2, 2007 What are you doing with this line? <input type='button' value = 'Get Totals' onclick='gettotals(this, \"$rowcnt\")' /> It appears that you are referencing a PHP variable from within javascript alone. That can't be done. You have to echo the PHP variable using PHP into the javascript position in which you wish it to be placed. Link to comment https://forums.phpfreaks.com/topic/45251-form-total/#findComment-219761 Share on other sites More sharing options...
Kano Posted April 3, 2007 Author Share Posted April 3, 2007 Hi there, Yes I forgot to include the php tags in the code i listed to save time. So that is not the problem. The code I listed is so that the form will get totals from all the item totals onclick in a for loop. But like all Javascript it never seems to work properly. Link to comment https://forums.phpfreaks.com/topic/45251-form-total/#findComment-220387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.