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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:29:05+00:00 2026-05-26T05:29:05+00:00

I am using a onclick function and adding a value to by paasing a

  • 0

I am using a onclick function and adding a value to by paasing a value to it. If the value already exists den i remove that value from the list.

function send_value(str)
    {
    //alert(str);
    var sub_id = document.getElementById('selected_sub_id').value;
    //alert(sub_id.indexOf(str));
    if(sub_id.indexOf(str)==-1)
    {
        if(sub_id=="")
        {
            sub_id+=str;
        }
        else
        {
        sub_id+=',';
        sub_id+=str;
        }
    }
    else
    {
        sub_id = sub_id.replace(str+",", "");
        sub_id = sub_id.replace(","+str, "");
        sub_id = sub_id.replace(str, "");
    }
    //alert(sub_id);
    document.getElementById('selected_sub_id').value=sub_id;
}

This is the function. Suppose i have the values 1,2,3,4 in the selected_sub_id and i am passing 5 to it, it will be stored as 1,2,3,4,5
now i am passing 24 it will be stored as 1,2,3,4,5,24
No suppose i want to remove 2, so when i send 2 to the function it removes all the occurrences of 2 so i am left with only 1,3,4,54…
kindly help me with this 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-26T05:29:05+00:00Added an answer on May 26, 2026 at 5:29 am

    You most probably want an array for this. It makes things much easier.

    Create one first:

    var arr = [];
    

    Adding goes with .push:

    arr.push(24);
    

    Removing goes with .splice and .indexOf (the 1 means ‘removing 1 element’):

    arr.splice(arr.indexOf(24), 1);
    

    Converting to a string goes with .join:

    arr.join(); // 1,2,3,24 or something similar depending on elements
    

    For example: http://jsfiddle.net/ScBNQ/.

    var arr = [];
    
    // adding
    
    arr.push(1);
    arr.push(2);
    arr.push(3);
    arr.push(24);
    
    // removing
    
    arr.splice(arr.indexOf(2), 1);
    
    // joining
    
    arr.join(); // 1,3,24
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a function that obtains a target element id at onclick. Example,
calling a js function using onclick... onclick=SubmitAge(66, 'ctl00_MainContent_arTo_upAgeRange') function just calls an updatePanel from
I'm adding a ckeditor to my form using the onclick functionality - i.e., when
Yes ive been told a couple of time using onclick $('#linkId').click(function() instead of <a
I'm using jqGrid and adding my own onclick event to each cell of data
What is the difference between using the OnClick attribute of an ASP.Net Button: <asp:Button
I am using elemntFromPoint in order to return onclick some element. I would like
how to handle button onclick action in iPhone without using interface builder?
A line created using the DrawLine method of wx.DC has the onClick and onMouseOver
Using ASP.NET MVC there are situations (such as form submission) that may require a

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.