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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:48:34+00:00 2026-06-12T14:48:34+00:00

I have 3 fields for user input.. say textbox1,textbox2,textbox3. What i need to do

  • 0

I have 3 fields for user input.. say textbox1,textbox2,textbox3. What i need to do is represent them like this if values are not empty:

Albany, New York, USA

The last textbox value shouldnt have a comma after that. I was able to do it with an associative array but the problem is i couldnt find a way to detect if it was the last value and after that the comma need not appear.Here is what i did

    var addressObjToFormat= {};
    addressObjToFormat.City = $("#companyentry").find("#City").val();
    addressObjToFormat.State = $("#companyentry").find("#State").val();
    addressObjToFormat.Country = $("#companyentry").find("#Country").val();

    var formattedAddress = $Utils.mapInfoMarkerAddressFormatter(addressObjToFormat);


   mapInfoMarkerAddressFormatter = function mapInfoMarkerAddressFormatter(arraddressObjToFormat) {
       var formattedAddress = '';
       for (var key in addressToFormatObj) {           
           if (addressToFormatObj.hasOwnProperty(key)) {
               if (addressToFormatObj[key] != '') {
                   formattedAddress += addressToFormatObj[key] + ',';                    
               }
           }
       }
       alert(formattedAddress);
   }

Above code gives me result as :

Albany, New York, USA,

Mumbai, Maharshtra, India,

What i want is it should be able to check if its the last field incase if a textbox is left empty and place comma accordingly after each value. Or is there a better way to do this?

  • 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-12T14:48:36+00:00Added an answer on June 12, 2026 at 2:48 pm

    There are multiple ways to do this

    After all your processing, you can just trim off the last ‘,‘ as using a regex

    formattedAddress = formattedAddress.replace (/,$/g, "");
    

    Alternatively, you can just push your strings into an array and then join them all.

    var tmp = [];
    for (var key in addressToFormatObj) {
        if (addressToFormatObj.hasOwnProperty(key)) {
           if (addressToFormatObj[key]) { // your condition
               tmp.push(addressToFormatObj[key]);
           }
        }
    }
    var formattedAddress = tmp.join(',');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like this, with three fields: User | Question# | Answer
I have a IceFaces-form and several input fields. Let's say I have this: <ice:selectOneMenu
Say I have a model like this public class User { [Required] [StringLength(14, ErrorMessage
I have a form with a few input fields. When a user clicks on
If I have this table TableABC and it has some fields/columns, rather say it
Say I have three fields for a user to enter a date: day, month,
Let's say we have a textbox that's readonly, like so: <input type=text readonly />
I have an input edit field where the user can enter data. I want
TABLE bcompany companyID | cName | ... I have the input field, where user
I have a model with the following fields: user = models.ForeignKey(User) impact = models.IntegerField(default

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.