综合技术

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

微信扫一扫,分享到朋友圈

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

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() {
       allVals.push($(this).val());
     });
     $('#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() {
        values.push(this.value);
    });
    $("#file-" + id).val(values.join(","));
});

DEMO: http://jsfiddle.net/fXMrj/52/

阅读原文...


微信扫一扫,分享到朋友圈

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

Hello, buddy!

WebGL, Fragment Shader, GHCJS and reflex-dom

上一篇

掘金 AMA - 听闲鱼客户端架构师宗心谈 Flutter 和他的团队

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

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

长按储存图像,分享给朋友