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.. Quote Link to comment 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. Quote Link to comment 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. 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.