Javascript change input field name in php -
i've got table inside form. table displaying first row form fields. in next field javascripts executes inserts row table. field named qty1 first row, javascripts executes , row added field name should become qty2, etc.
in form results page not pulling through qty2 input field value, qty1. doing wrong. not javescript expert.
first row:
$x = 1; echo '<tr>'; echo '<td><input type="text" name="qty' . $x . ' id="qty" size="6"/></td>'; echo '<td><input onfocus="grndtot()" type="text" name="grandtot1" id="grandtot1" size="10" readonly/></td>'; echo '</tr>';
then function insert row
function grndtot() { var table = document.getelementbyid("mytable"); var row = table.insertrow(2); var cell1 = row.insertcell(0); var cell2 = row.insertcell(1); cell1.innerhtml = cell1.innerhtml = <?php $x++; echo json_encode("<input type="text" name="qty' . $x . ' id="qty" size="6"/>"); ?>; cell2.innerhtml = " "; }
on results page
echo $_post['qty1']; echo $_post['qty2'];
then seeing qty1 results.
instead of numbering field names can make them arrays. each row of table you'd have new array index, e.g.
row 1:
<input type="text" name="qty[]">
row 2:
<input type="text" name="qty[]">
when php gets hold of $_post
data it'll multidimensional array. 2 quantity fields accessible this:
echo $_post['qty'][0]; echo $_post['qty'][1];
Comments
Post a Comment