html javascript, multiply the values of a dynamic row -


i've dynamically created rows in table using javascript i've altered suit needs, within dynamically created table want multiply qty price , put in total box,

html

<table>            <tbody id="platevolumes">         <tr>             <td><input type="checkbox" value="none" id="chk" name="chk[]" /></div></td>             <td><input type='text' name='qty' id='qty' class="qty" placeholder='qty' /></td>             <td><select name="productdescription[]" class="productdescription" id="productdescription">                 <option value="product">product</option>                 <option value="product01" label="product01">product01</option>                 <option value="product02" label="product02">product02</option>                 <option value="product03" label="product03">product03</option>                 <option value="product04" label="product04">product04</option>                 <option value="product05" label="product05">product05</option>                 <option value="product06" label="product06">product06</option>                 </select></td>             <td><input type='text' name='price[]' id='price' class="price" placeholder='price (&pound;)' onchange="wo()" /></td>             <td><input type='text' name='totalprice[]' id='totalprice' class="price" placeholder='total price&nbsp;(&pound;)' /></td>         </tr>     </tbody> </table> 

i using javascript code in order add values work first line isn't created code:

javascript

<script> function wo() {  var qty = document.getelementbyid('qty').value;  var price = document.getelementbyid('price').value;  answer = (number(qty) * number(price)).tofixed(2);    document.getelementbyid('totalprice').value = answer;    } </script> 

i'm pretty new javascript i'm wondering if there way apply dynamic rows keep them separate when pass them on php mailer.

edit: i've been playing code , i'm bit closer getting answer need still don't know how make give me answers want,

function wo() { (var = 0; < rowcount; i++) {  var qty = document.getelementsbyclassname('qty').value;  var price = document.getelementsbyclassname('price').value;  var answer = (number(qty) * number(price)).tofixed(2);  document.getelementsbyclassname('totalprice[' + + ']').innerhtml = answer; } } 

in html id should unique. when element id returns first element gets.

i suggest use class in stead. run loop rows , calculate total.

this closer solution... have not tested though.

    var trnodes = document.getelementbyid('platevolumes').childnodes;     for(var i=0; < trnodes.length; i++) {          var qty = trnodes[i].getelementsbyclassname('qty').value;          var price = trnodes[i].getelementsbyclassname('price').value;          var answer = (number(qty) * number(price)).tofixed(2);          trnodes[i].getelementsbyclassname('totalprice').innerhtml = answer;     } 

reference


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -