Copy the value of the Dynamic ID checkbox to the hidden input value by using jquery

综合技术 2018-07-22 阅读原文

I'm sooo... close but am stuck on one tiny thing that's probably really simple for you. The idea is to add the value of each checkbox to the hidden field's value.

The moment I add a second (or more forms) with their own variable ID's, it falls apart. I know the first part of the jQuery code works but I don't know how to get loader_id
into here.

$('#fileset-'+ loader_id +' input').click(updateFileField);

I think
that is where I'm messing up because if I hard code the id here the rest works beautifully.

The following is the full code and can also be found here

File 1
File 2 ​

Here's the jQuery portion

function updateFileField() {

 var allVals = [];
 var loader_id = $(this).parent('div').attr('id').replace('fileset-', '');
     $('#fileset-' + loader_id + ' :checked').each(function() {
     $('#file-' + loader_id ).val(allVals);
 $(function() {
     $('#fileset-'+ loader_id +' input').click(updateFileField);


Thanks for your help!

Is that you've been looking for?

$(".fileset :checkbox").on("change", function() {
    var div = $(this).parent();
    var id = div.attr("id").split("-")[1];
    var values = [];
    div.find(":checked").each(function() {
    $("#file-" + id).val(values.join(","));


Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!


deep extend (like jQuery’s) for nodeJS I am struggling with deep copies of objects in nodeJS. my own extend is crap. underscore's extend is flat. there are rat...
jquery function not work iam creating accordion menu with jquery + css3 everything going fine expect that the menu always open when...
jquery表单序列化 $(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: "t...
Change the color of the selected option – jQ... I want to change the text color of the option that is selected="selected": -- 2014 2013 ...
Submit an image file with an ajax / json b... Is there anyway of submitting a file uploaded via Ajax/json/jQuery? is there a plug in at all? if I want to submit oth...