我得到这个JavaScript的错误,我需要做的是动态添加下拉列表中的onchange
行。即每次点击“添加更多”按钮,根据下拉菜单的变化添加行并获得文本框的值。JavaScript:Uncaught SyntaxError:missing)在使用onchange事件添加行时参数列表
$(document).ready(function() {
var a = 1;
$('.tab_new').on('change', '.product_name', function() {
var product_code = $('#product_name' + a).val();
$.ajax({
type: "get",
url: 'price.php',
data: {
product_code: product_code
},
dataType: 'json',
success: function(data) {
if (data) {
$('#product_price' + a).val(data)
}
}
});
});
$("#add").click(function() {
a = a + 1;
$('#datatables tr').eq(-2).after('<tr><td><input type="text" name="client_name[]" value="" id="client_name' + a + '"/></td><td ><select class="product_name" name="product_name[]" id="product_name' + a + '" ><option value=""> --------all-------- </option> <?php $result=mysql_query("select * from product_form"); while($row = mysql_fetch_row($result)) { echo "<option value='
$row[0]
'> $row[1] </option>"; } ?></select></td><td ><input type="number" name="product_price[]" value="" id="product_price' + a + '" class=".product_price"/></td></tr>');
});
});
HTML:
<table id="dataTables" class="tab_new">
<thead >
<tr>
<th>CLIENT NAME</th>
<th>PRODUCT NAME </th>
<th>PRICE </th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="client_name[]" value="" id="client_name"/></td>
<td><select name="product_name[]" id="product_name1" class="product_name">
<option value=""> --------ALL-------- </option>
<?php $result=mysql_query("Select * from product_form");
while($row = mysql_fetch_row($result))
{
echo "<option value='$row[0]'> $row[1] </option>";
} ?>
</select></td>
<td><input type="number" name="product_price[]" value="" id="product_price1" class="product_price"/></td>
</tr>
</tbody>
</table>
<br><br><br>
<input type="submit" name="submit" value="Save">
<input type="button" id="add" value="Add More" />
I am getting an error missing argument when i clicked on the button .
还提供HTML代码 –
你试图通过你的JS代码打印PHP解决上述错误。为什么? 另外,$行在JS范围中没有定义,但在这里用作变量。 –
您的PHP在该字符串的中间输出换行符吗? – nnnnnn