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

  • SEARCH
  • Home
  • 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 8462997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:20:31+00:00 2026-06-10T14:20:31+00:00

How to concatenate values to the hdnfield value with comma on checkbox click event.

  • 0

How to concatenate values to the hdnfield value with comma on checkbox click event. when i click the checkbox i select order and passit to the JS function. If i select three checkboxes the hdnfield value should be like 1, 2, 3… something like that… how to do that?

if (chkBoxOne != null) 
{
    chkBoxOne.Attributes.Add("onclick", "javascript:return SelectOne('" + chkBoxOne.ClientID + "','" + e.Row.ClientID + "','" + lblorderId.Text + "')");
    //if (chkBoxOne.Checked)
    //    hdSelectAllOrderId.Value += ((Label)e.Row.FindControl("lblorderId")).Text + ",";
}


function SelectOne(id, rowID, OrderID) {
  var AllOrderIDs = 0;
  AllOrderIDs = Number(document.getElementById('ctl00_PagePlaceholder_hdSelectAllOrderId').value);
  alert(AllOrderIDs);
  if (document.getElementById(id).checked == true) {
      if (AllOrderIDs == '')
          AllOrderIDs = OrderID;
      else
          AllOrderIDs = AllOrderIDs + ' ,' + OrderID;
}
alert(AllOrderIDs);}

The above code is not working. when i click on the firt checkbox its showing frist ordid, but when i click on the second one its not showing first ordid which is i already assigned to it. Its just showing second one…

   var AllOrderIDs = 0;
AllOrderIDs = document.getElementById('ctl00_PagePlaceholder_hdSelectAllOrderId').value;
var IDs = AllOrderIDs.split(',');
if (document.getElementById(id).checked == true) {
    if (IDs.indexOf(OrderID) == -1) {
        IDs.push(OrderID);
    }
}
else {
    var index = IDs.indexOf(OrderID);
    if (index != -1) {
        IDs = IDs.slice(index, 1);
    }
}
AllOrderIDs = IDs.join(',');
  • 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-06-10T14:20:33+00:00Added an answer on June 10, 2026 at 2:20 pm

    First of all, yes, you forgot to save the value to hidden field.
    Second, you are only handling the situation, when the checkbox state changes to “checked”. thus, you don’t delete IDs from hidden field. If you check-uncheck-and-check-again, you will have duplicate ID saved.
    I recommend you to split your string into array of IDs and then work with it.

    <html>
    <head>
    <script type="text/javascript">
    function Select(sender, OrderID)
    {
        var AllOrderIDs = document.getElementById('hf1').value;
        var IDs = AllOrderIDs.split(',');
        if (sender.checked == true)
        {
            if (IDs.indexOf(OrderID.toString()) == -1)
            {
                IDs.push(OrderID);
            }
        }
        else
        {
            var index = IDs.indexOf(OrderID.toString());
            if (index != -1)
            {
                IDs.splice(index, 1);
            }
        }
    
        AllOrderIDs = IDs.join(',');
        alert(AllOrderIDs);
        document.getElementById('hf1').value = AllOrderIDs;
    }
    
    function Check()
    {
        var AllOrderIDs = document.getElementById('hf1').value;
        alert(AllOrderIDs);
    }
    
    </script>
    </head>
    <body>
    <input type="hidden" id="hf1" />
    <input type="checkbox" id="check1" onclick="Select(this, 1);" />
    <input type="checkbox" id="check2" onclick="Select(this, 2);" />
    <input type="checkbox" id="check3" onclick="Select(this, 3);" />
    <br />
    <p> <input type="button" onclick="Check();" value="Check" /> </p>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to concatenate values by comma when I will use group by.
Is there a way in MySQL to concatenate text to values using a SELECT
I am trying to select multiple column values and concatenate them into one column.
Possible Duplicate: Concatenate row values T-SQL I have a table like this: ref_num name
Possible Duplicate: Concatenate row values T-SQL I'm new to SQL Server and had tried
As part of a homework assignment I need to concatenate certain values in an
In python, you can concatenate boolean values, and it would return an integer. Example:
Possible Duplicate: Concatenate Two NSDate String values Just confused that is there any default
I have 7 integer values (with 3,1,3,4,4,5,4 digits respectively) and I have to concatenate
I'm asking about the right way to concatenate a url with values ! here

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.