how to fetch values from array input in javascript -


how fetch values array in javascript:

<html> <head>     <script type="text/javascript">         function proc()         {             var cost = document.yoh.coz.value;             var qtybuy = document.yoh.qbuys.value;             var st = cost * qtybuy;              var tbox = document.yoh.subtotal;             if (tbox)             {                 tbox.value = st;             }         }     </script> </head> <body>  <?php     include('conn.php');      $prodname = $_get['prodname'];     $result = query_database("select * prod_table product='$prodname'", "onstor", $link); ?> <?php while ( $row = mysql_fetch_array($result) ) { ?>  <form name="yoh" method="get">     product id: <input type="text" name="prodid" value=""><br/>     cost: <input type="text" name="coz" value="<?php echo $row['s_price']; ?>"><br/>     quantity buy:<input type="text" name="qbuys" value="" onkeyup="proc();"></br>      subtotal:<input type="text" name="subtotal" value=""></br> </form>  </body> <?php } ?> </html> 

as can see program multiply 2 values. 1 of values fetched database, , other comes user. if way, don't results:

<html> <head>     <script type="text/javascript">         function proc()         {             var cost = document.yoh.coz[].value;             var qtybuy = document.yoh.qbuys[].value;             var st = cost * qtybuy;              var tbox = document.yoh.subtotal[];             if (tbox)             {                 tbox.value = st;             }          }     </script> </head> <body> <?php     include('conn.php');      $prodname = $_get['prodname'];     $result = query_database("select * prod_table product='$prodname'", "onstor", $link); ?> <?php while ( $row = mysql_fetch_array($result) ) { ?>  <form name="yoh" method="get">     product id: <input type="text" name="prodid[]" value=""><br/>     cost: <input type="text" name="coz[]" value="<?php echo $row['s_price']; ?>"><br/>     quantity buy:<input type="text" name="qbuys[]" value="" onkeyup="proc();"></br>      subtotal:<input type="text" name="subtotal[]" value=""></br> </form>  </body> <?php } ?> </html> 

do need include index manually? need achieve same results when using arrays.

you can use name value:

cost=document.yoh.elements['coz[]'].value; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -