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 6055769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:05+00:00 2026-05-23T08:18:05+00:00

<input type=hidden id=values value=1,2,1,3 /> <a href=# id=add data-value=4>add</a> <a href=# id=remove data-value=1>remove</a> <script

  • 0
<input type="hidden" id="values" value="1,2,1,3" />

<a href="#" id="add" data-value="4">add</a>

<a href="#" id="remove" data-value="1">remove</a>

<script type="text/javascript">
$(document).ready(function()
{
    $('#add').click(function()
    {
        var value = $(this).attr('data-value');

        //add to $('#values')

        return false;
    });

    $('#remove').click(function()
    {
        var value = $(this).attr('data-value');

        //remove all values that match in $('#values');

        return false;
    });
});
</script>

Examples

a) Add, output would be: 1,2,1,3,4

b) Remove, output would be 2,3

  • 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-23T08:18:06+00:00Added an answer on May 23, 2026 at 8:18 am

    You can achieve this with basic JavaScript functions and some jQuery goodies. Have a look at the documentation of the individual functions to learn more about them.

    Add:

    $('#values').val(function(i, v) {
        var arr = v.split(',');
        arr.push(value);
        return arr.join(',');
        // or actually easier in this case:
        // return v ? v + ',' + value : value;
    });
    

    Remove:

    $('#values').val(function(i, v) {
        return $.grep(v.split(','), function(v) { 
            return v != value; 
        }).join(',');        
    });
    

    Reference: val, split, push, join, grep

    DEMO

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

Sidebar

Related Questions

I have the following and in this order: <script type=text/javascript> $(document).ready(function(){ var overwrite =
I have below html code in my aspx. <input type=hidden id=medicalLink value='<a href=/forms/contactus.aspx >Contact
I have an hidden input field with a value, <form> <input type=hidden value=product/> <select
I have the following HTMl: <input id=brandID name=brandID type=hidden value= /> <select id=selectList class=textfield70pc
Which should I use? <input type=hidden name=first_name value=<%= person.first_name %> /> or <input type=hidden
<body> <div> <?= $_POST['msg'] ?> </div> <form id=frm method=post> <input type=hidden name='msg' value='{field0: Im
How can I get rid of: <input type=hidden name=__VIEWSTATE id=__VIEWSTATE value=.../> Completely !
The page I'm trying inspect has a hidden <input type=hidden name=Foo value=123 /> element
$regexp = '/(?:<input\stype=hidden\sname=){1}([a-zA-Z0-9]*)(?:\svalue=1\s\/>)/'; $response = '<input type=hidden name=7d37dddd0eb2c85b8d394ef36b35f54f value=1 />'; preg_match($regexp, $response, $matches); echo
I have the below code in my .aspx page. <input type=hidden id=fbinfo name=fbinfo value=

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.