Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3422638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:16:15+00:00 2026-05-18T06:16:15+00:00

<form> <input type=checkbox id=01 name=01 /> <input type=checkbox id=02 name=02 /> <input type=checkbox id=03

  • 0
<form>

    <input type="checkbox" id="01" name="01" />
    <input type="checkbox" id="02" name="02" />
    <input type="checkbox" id="03" name="03" />

    <input type="hidden" value="03,01," />

</form>

I have the form above; checkboxes 01 and 03 are ticked when the page has finished loading using the code below.

I now need to ensure that when the value of the checkboxes change, so too does the hidden CSV field (though this could perhaps be done when the form submits?). I think that using the variables created, it should be possible to re-populate the CSV field when the form submits. ie, using selected_ids to add the ids of the checked boxes onto the end of the CSV (if they aren’t already present). Can this be done?

var csvValue = $('#csv-input').val();
var selected_ids = csvValue.split(',');
for (var i = 0; i < selected_ids.length; i++)
{
    var selected_id = selected_ids[i];
    $('#' + selected_id).attr('checked', 'checked');
}

Some kind person gave me this code in my previous question:

$(':checkbox').bind('change', function(event){
    if (this.checked == true){
      // add to hidden field
      var tempIdStr = $('#cvs-input').val();
      // if not in hidden value already
      if (tempIdStr.indexOf(this.id) > -1){
          tempIdStr += "id,"; // or ", id" depending on how you are seperating the ids
         $('#cvs-input').val(tempIdStr);
      }
    } else {
    // remove from hidden field
      var tempIds = $('#cvs-input').val().split(',');
      var index = tempIds.indexOf(this.id);
      if (index > -1){
          tempIds.splice(index, 1);
          $('#cvs-input').val(tempIds.join(',');
    }
});

Which I think is close, but isn’t quite there yet. Any further help on this would be great, thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:16:16+00:00Added an answer on May 18, 2026 at 6:16 am

    You can build a CSV from element attributes concisely using .map:

    $(":checkbox").change(function() {
        var csv = $(":checkbox:checked").map(function() {
            return this.id;
        }).get().join(",");
        alert(csv);
        $("input:hidden").val(csv);
    });
    

    Demo: http://jsfiddle.net/karim79/tqAnX/2/

    As a side-note, element IDs should not begin with numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following: <form id=my_form> <input type=checkbox name=a value=a> Check <img src=... />
<form> <input type=checkbox id=m_q name=m_q value=271>Name</input><div name=status></div> <input type=checkbox id=m_q name=m_q value=271>Age</input><div name=status></div> <input
I have this page which loads quotes. It has a search form wherein if
I am trying to make a page that allows users to select 8 checkboxes
I am busy getting values on a form using jQuery to send to my
I'm trying to write a jQuery script (I have never written one before and
I have a set of custom PHP forms within a set of Drupal pages
I have a list of 3 radio buttons with the 1st radio that's selected
I am using the MySQL table below. I would like to add a field
We're building a web app, and it's using jquery ajax and jsp on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.