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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:06:27+00:00 2026-06-02T02:06:27+00:00

how can concatenate the set variable in a for loop to be use as

  • 0

how can concatenate the set variable in a for loop to be use as name in an input to get the value?

<script>
var k=0;
var counter = 50;

    for(k=0; k<=counter; k++){
        var choices = $('input[name=choices'+ k]).val();
        var choices = choices.replace(/\ /g, '%');
        var choices_ = choices_ +";"+ choices;
    }
   alert(choices);
</script>

there are multiple input field namely choices1,choices2 and so on.
how can i get the value of those fields using for loop?
how can i concatenate the name choices and the variable k?
can you help me solve this problem??

  • 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-02T02:06:28+00:00Added an answer on June 2, 2026 at 2:06 am

    You could always just iterate using a specialized attribute selector and .each():

    var choices = $('input[name^="choices"]'),  // name starts with "choices"
        choices_val = []                        // an array!
        ;
    
    choices.each(function () {
        choices_val.push($(this).val().replace(/\ /g, '%'));
    });
    
    alert(choices_val.join(';'));
    

    It saves you the overhead (and headache) of having to pick out and mangle a specific attribute value (choices1, choices2, etc) and having to select it out via selector (’cause I’d think that selecting via $(this) is faster than $('input[name="choices1"]')).

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

Sidebar

Related Questions

How can i concatenate var names to declare new vars in javascript?: var foo
I'm attempting to set up a script to concatenate some variables inside a string
I have the following code: class Person { public String Name { get; set;
In python, you can concatenate boolean values, and it would return an integer. Example:
How can I concatenate two char columns within a perform screen? example: table sample
How can I get tar/cp to copy only files that dont end in .jar
I try to use VIM build my SQL query by concatenate block of strings.
I can easily concatenate two variables, foo and bar, as follows in Tcl: ${foo}${bar}.
I have a class: public class LabOccurrenceForm { public DateTime Occurrence_Date { get; set;
I have a set of js files I concatenate into a unique file at

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.