Jump to content

Kano

Members
  • Posts

    76
  • Joined

  • Last visited

    Never

Everything posted by Kano

  1. Hi there, how does javascript add to a input text box the value (1.05) when a checkbox is checked and the value (0.00) when not checked, thanks for any help.
  2. Kano

    Form total

    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.
  3. 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..
  4. Hi there, Wanting to add a button to my form so when the user selects it the grand total input value = all input values whos name is index of "subtotal_". Have tried many other ways of achieving this but with no success so I think this is the best way to get the totals. The subtotal_ is a value gotten using javascript (price * qty(<select>). Can any one help? thanks.
  5. HI there, Can someone help me please, this code works fine but I wish to add a function which adds all the <total_$wsi_id> values up and creates a grand total?? <script> function calc(obj, wsi_id) // function to create total of each order line { var ans = (obj.form.elements['price_'+wsi_id].value) * (obj.form.elements['qty_'+wsi_id].value); var res = ans.toFixed(2); obj.form.elements['total_'+wsi_id].value = res; } </script> <body> ..... while($row_getwsi = mysql_fetch_array($sqlres_getwsi)) { extract($row_getwsi); // create order line echo " <td> <input type = 'text' name = 'price_$wsi_id' value = '$wsi_price' readonly =' readonly' size = '6' maxsize = '7' /> </td> <td> <select name = 'qty_$wsi_id' onchange = 'calc(this, \"$wsi_id\")'>"; // create order line total for($selectcnt=0;$selectcnt<=$wsi_qty;$selectcnt++) { echo "<option value='$selectcnt'"; if($_SESSION[$wsi_id] == $selectcnt) { echo "selected='selected'"; } echo">$selectcnt</option>"; } echo "</select></td>"; echo"<td>$wsi_id</td> <td>$wsi_dim</td> <td><input type = 'text' name = 'total_$wsi_id' readonly = 'readonly' /> </td>"; .... <tr><td>Grand Total</td><td><input type="text" name="g_total" /></td></tr> // I wish this part to total all the order lines. .... thanks.
  6. Hi there, Can someone help me please. I have an order form in which PHP freaks kindly helped me build a while back, but I am having problems with including a grand total to the form. Each line of the form has a sub-total which javascript works out by * the qty (select tag) with the price, the javascript is 'onchange' on the select tag. Now i want the forms grand total input box to = all the sub-total input boxes. Would this be done within the same javascript function on the select tags (i.e every time there is a change work out grand total)? The sub-totals have a name="subtotal_$wsi_id" (i.e. sub-totals have an index of subtotal_) The grand-total has a name="grandtotal" Many thanks.
  7. hi there, Was wondering if someone new how to stop text in a <td> from adjusting: This is text on page. to this: This is text on page. thanks.
  8. Hi there again Fenway, Problem solved - what i have do is changed the onchange = 'calc(this, \'$wsi_id\')' TO onchange = 'calc(this, \"$wsi_id\")' And it likes it, don't know why but it does?? Thanks for your time.
  9. Sussed it!!!! Woooooooooo Added attribute value="0" ect... to the options in the select, now IE likes that?? Thanks for your help Fenway. I am sure its not the end...
  10. I have added the toFixed function to round to 2 decimals but still same problem in IE (0.00), FireFox is fine.
  11. Hi there, You are right is does work in FireFox, try it in IE!! Anyone know why it gives the result as 0 in IE?? thanks.
  12. Hi there, I have recreated this problem in static HTML to see if I can find any problems. The problem I am now getting at the moment is onchange the total is calculated to 0 every time, here is the code: <script> function gogo (obj) { obj.form.elements['total_VB001'].value = (obj.form.elements['price_VB001'].value) * (obj.form.elements['qty_VB001'].value); return; } </script> <form id="orderform" name="orderform" method="post" action=""> <table><tr><td> <input type="text" name="price_VB001" value="122.99" readonly="readonly" /></td><td> <select name="qty_VB001" onchange="gogo(this)"> <option selected="selected">0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select></td><td> <input type="text" name="total_VB001" readonly="readonly" /></td></tr> </table> </form> Any ideas what is wrong with this? Thanks.
  13. Hi there Fenway, I take it 'obj' holds 'this' which means this 'document'? And when the select input changes it then reads the function and adds the total of the sum to the input box total. Should there be any brackets around the sum? Should there be a semi-colon after the sum? Should there be <!-- --> in the <script>? Maybe I will run the script through FireFox instead of IE and see what happens. It looks like it should work? I cannot see any reason to suggest otherwise?
  14. Hi there fenway, No JS errors. It just does not register anything?
  15. Genius! Nice one mate! You wan't to see what I had, haha. Thanks
  16. Hi there, I wish to unset some but not all $_SESSION variables. for example, i wish to keep $_SESSION['auth'] and $_SESSION['wscemail'] and destroy all others. can someone help? thanks.
  17. Sorry for delay, T'Interent down at home, Only access during working hours (GMT). <head> <script> function calc(obj, wsi_id) { obj.form.elements['total_'+wsi_id].value = obj.form.elements['qty_'+wsi_id].value * obj.form.elements['price_'+wsi_id].value; } </script> </head> <body> ... same as before only: <input type = 'text' name = 'price_$wsi_id' value = '$wsi_price' readonly='readonly' /> <select name='qty_$wsi_id' onchange='calc(this, \'$wsi_id\')'> <input type = 'text' name = 'total_$wsi_id' readonly='readonly' /> </body> Thanks.
  18. Having problems with this Fenway, it does not seem to work.
  19. Hi there, Is there another way of writing this function because I do not want it to go through all the $fields, I just want to loop through fields with an index of: qty_ thanks.
  20. Hi there Fenway, Thank-you for your time. I will let you know how I get on.
  21. Hi Fenway, Wonder if you could help me with this please, below is part of the php that creates the form (named order), I am trying to write some javascript that will multiple the price with the selected qty onblur but cannot seem to find the elements as you know, thanks for your help. // get product records in order of brand then range $sqlqry_getwsi = "select * from tbl_wsi order by wsi_brand, wsi_range"; $sqlres_getwsi = mysql_query($sqlqry_getwsi) or die ("Could not execute getwsi query"); // for each row fetched while($row_getwsi = mysql_fetch_array($sqlres_getwsi)) { extract($row_getwsi); // print row of items echo "<tr><td><img src='$wsi_tn' /></td> <td>$wsi_id</td> <td>$wsi_desc</td> <td>$wsi_dim</td> <td><input type = 'text' value = '$wsi_price' readonly='readonly' /></td> // item price <td><select name='$wsi_id'>"; // item qty ordered, name contains VA001, VB002, VE001, LR005 etc... // create options for($selectcnt=0;$selectcnt<=$wsi_qty;$selectcnt++) // loop till stock qty exceeded { echo"<option value='$selectcnt'"; // remember qty selected if user needs to edit order form if($_SESSION[$wsi_id]==$selectcnt) { echo "selected='selected'"; } // end if echo">$selectcnt</option>"; } // end for echo "</select></td> <td><input type = 'text' /></td>"; } // end while
  22. Here is something I am working on: function calc() { for (var num=0;num<getElementByTagName("select").length;num++) { document.formname.elements[num+2].value = (document.formname.elements[num+1].value) * (document.formname.elements[num].value) // total (3rd element in the row) = price (2nd) * qty (1st) } } would this work??
  23. the name of the select is a php variable using data from mysql, so I can remember the selection if the user cancels order processing and edits the form. On the form I want to keep running totals for item quantity*price etc... the quantity is a select tag and the price is a readonly input "text" tag. for each item row i would like total cost but i do not know how many item rows there are because the script is built so that i can add more items through mysql. so i need javascript to go through the elements and create the total, i am thinking maybe element by tag name or something??
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.