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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:04:40+00:00 2026-06-15T17:04:40+00:00

I’ve got a Rails app in to which I want to submit a series

  • 0

I’ve got a Rails app in to which I want to submit a series of comma-separated IDs in a text field. For instance, let’s say I was adding three elements to an order w/ respective IDs 12, 2, and 4, I would like the field to read:

12,2,4

Which is easy enough. The problem shows up when I’ve changed my mind and I want to replace an element in a certain position, i.e., the start, to an element with an ID of let’s say 3. How would I manage to submit 3,2,4 and not 2,4,3? I’m pretty stuck. And if there’s a method of automatically putting commas only between the IDs (not at the start or the end) in the field that’d be hugely useful.

Cheers!

Edit: I’ve written this in an attempt to solve this problem. It feels close but no cigar yet. The src mentioned below contains one of the three IDs mentioned above, and there is a changing number of the #elementXs to which this function will be attached.

$('#element1').change(function() {
  var src = $(this).val();
  var array = $('#order').val().split(",");
  array.splice(0, 1, src).join(",");
  $('#order').val(array);
}
  • 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-15T17:04:41+00:00Added an answer on June 15, 2026 at 5:04 pm

    Three steps. You’re starting with a string containing comma-separated integers.

    1. Split the string on the commas into an array of ids.
    2. Splice the new id into the array replacing the old id. You want to pass 3 parameters to splice:
      • The index of the element you want to start removing from (if you want to remove the first element, its index would be 0).
      • How many elements you want to remove (here you just want to remove the first element, so 1).
      • The new element to add in (in your case, it’s src).
    3. Join the string back together on a comma.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.