JavaScript数组这是我的HTML代码如何创建HTML表单数组元素
<table width="62%" height="70" border="1" cellpadding="0" cellspacing="0" id="edit">
<?php if(count($voucher_info) > 0){ ?>
<tr class="bgcolor_02">
<td width="27%" align="center" class="admin" >S.no</td>
<td width="37%" align="center" class="admin" >Voucher Type</td>
<td width="47%" align="center" class="admin" >Voucher Mode</td>
</tr>
<?php
$rownum = 1;
foreach($voucher_info as $eachrecord){
$zibracolor = ($rownum%2==0)?"even":"odd";
?>
<tr align="center" class="narmal">
<td height="25"><?php echo $eachrecord->voucher_id ; ?><input type="hidden" name="voucher_id[]" value="<?php echo $eachrecord->voucher_id; ?>" /></td>
<td><input name="vouchertype[]" type="text" value="<?php echo $eachrecord->voucher_type; ?>" id="vouchertype"/></td>
<td><select name="mode[]" >
<option value="paidin" <?php if($eachrecord->voucher_mode=='paidin'){ ?> selected="selected" <?php } ?>>Paid In</option>
<option value="paidout" <?php if($eachrecord->voucher_mode=='paidout'){ ?> selected="selected" <?php } ?>>Paid Out</option>
</select></td>
</tr>
<?php
}
}
else{
echo "<tr class='bgcolor_02'>";
echo "<td align='center'><strong>No records found</strong></td>";
echo "</tr>";
}
?>
</table>
<input id="update" type="submit" name="submit" value="Edit"/>
我只是想知道我怎么访问vouchertype和模式在JavaScript中,并通过他们使用Ajax控制器。我想将更新的值保存到数据库。请有人有任何想法,然后告诉我。
您可以使用Ajax提交后到PHP和处理它有 – 2015-02-10 05:09:08
您可以随时AJAX发布Javascript数组,并在服务器端,你可以收集。例如你有一个数组myArr = [“Sunday”,“Monday”,“Tuesday”]'只需使用ajax发送'$ .ajax({url:“/ post.php”,type:'POST', data:{theArray:myArr}},success:function(resp){alert(JSON.stringify(resp));}})'在服务器上,你会像'$ thearray = $ _POST ['theArray']; '。你试过这个吗?如果不是AJAX,那么尝试只是正常发布表单? – amitthk 2015-02-10 06:02:10
你试过[PHP:foreach](http://php.net/manual/en/control-structures.foreach.php)吗?像这样:'foreach($ mode_value as $ value){echo“Value:$ value
\ n”;/*在这里插入$值* /}'。 – amitthk 2015-02-10 06:11:57