[英]Append value to input field using jQuery
I have a small form with three fields and I can submit that form choose different options next time. 我有一个包含三个字段的小表格,下次我可以提交该表格,选择其他选项。 I am submitting this form with ajax call.
我正在使用ajax电话提交此表格。
Now on form submit I want to post all the selected options. 现在在表单提交中,我要发布所有选定的选项。 For this, I have created a hidden field like
为此,我创建了一个隐藏字段,例如
<input type="hidden" name="selectedproduct[]" id="sel-product">
and ajax success method am appending value like 和ajax成功方法正在附加像
$('#sel-product').val(element.product);
But here I am getting only one value instead of an array. 但是在这里,我只得到一个值,而不是数组。 How can I append all the values to the field?
如何将所有值附加到字段?
Assuming the product fields with class ".element_product". 假设产品字段的类别为“ .element_product”。
//init the array products
arrp=[];
//loop the elements
$('.element_product').each( function ()
{
arrp.push( $(this).val() );
});
//Pass the array to field
$('#sel-product').val(arrp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.