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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:06:17+00:00 2026-06-05T05:06:17+00:00

Ok, I have really confused myself. We have this app that concates values and

  • 0

Ok, I have really confused myself.

We have this app that concates values and sends them to TA box. I want to determine if the field has a value in it first,

  • if it does have a value, add it to TA field
  • if it does not have a value/empty, do not add it to the
    TA field,

How do i do this?

I want to use this on the blur event[see code example]. I know I need to use .each(), check length and/or look into each field, see if there is a value, if there is, put in TA field

Could someone show me how to accomplish this please?

jsfiddle >> http://jsfiddle.net/justmelat/6JHRT/

HTML

<form>
    <p>First name: <input type="text" name="firstname" id="firstname" value="Paul"/></p>
    <p>Last name: <input type="text" name="lastname"  id="lastname" value="Ryan" /></p>
<p>Street #: <input type="text" name="street_number"  id="street_number" value="4605"/></p>
<p>Address: <input type="text" name="address" id="address"/></p>
<p>City: <input type="text" name="city" id="city" /></p>
<p>State: <input type="text" name="state" id="state"/><br />

<span id="myzip">Zip:</span> <input type="text" name="zip"  id="zip" />
<br /><br />
<select name="hometype" id="hometype">
<option value="">Select</option>
<option value="SFH">Single Family Home</option>
<option value="Condo">Condo</option>
<option value="Trailer">Trailer</option><br />
</select><br />
<input type="radio" name="ownership" value="own" /> Own
<input type="radio" name="ownership" value="rent" /> Rent
    <hr />
<span id="allInfo">All Info:</span> <textarea id="ta_holdAll" rows="10" cols="30"></textarea><div id="charCnt"></div><br /><br />
    <input type="button" value="Add to Field" id="addField">
</form>​

JQUERY

$(document).ready(function(){

    function combineFields(event) {
      var mytextareaFld = $('#ta_holdAll');
      var fld_1 = $('#firstname').attr('name')+':  '+$('#firstname').val();
      var fld_2 = $('#lastname').attr('name')+':  '+$('#lastname').val();
      var fld_3 = $('#street_number').attr('name')+':  '+$('#street_number').val();
        var hold_all_fields = fld_1 +'\n' + fld_2 +'\n' + fld_3;
      //hold_all_fields.each();
      mytextareaFld.val(fld_1 +'\n' + fld_2 +'\n' + fld_3);
  }

    $('#addField').on('click',combineFields);

    $('#allInfo').on('click',function(event){
        combineFields(event);
        var $mytextareaFld = $('#ta_holdAll');
        var $outPutCount = $("#charCnt");
        var $ofText = " characters of 1000 remaining";
        var val = $mytextareaFld.val();
        var val2 = $outPutCount.text(val.length).append("<strong>"+$ofText+"</strong>");
    });

    $("#firstname,#lastname, #street_number").blur(combineFields);
});

​

  • 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-05T05:06:18+00:00Added an answer on June 5, 2026 at 5:06 am

    Try this — just check if the field exists (has length), and if it doesn’t, use an empty string:

    function combineFields(event) {
        var mytextareaFld = $('#ta_holdAll');
        var fld_1 = $('#firstname').val().length ? $('#firstname').attr('name') + ':  ' + $('#firstname').val() + '\n' : '';
        var fld_2 = $('#lastname').val().length ? $('#lastname').attr('name') + ':  ' + $('#lastname').val() + '\n' : '';
        var fld_3 = $('#street_number').val().length ? $('#street_number').attr('name') + ':  ' + $('#street_number').val() + '\n' : '';
        var hold_all_fields = fld_1 + fld_2 + fld_3;
        mytextareaFld.val(hold_all_fields);
    }
    

    http://jsfiddle.net/6JHRT/3/

    For added usefulness, use jQuery.trim() to wipe out blank spaces:

    function combineFields(event) {
        var mytextareaFld = $('#ta_holdAll');
        var fld_1 = $.trim($('#firstname').val()).length ? $('#firstname').attr('name') + ':  ' + $('#firstname').val() + '\n' : '';
        var fld_2 = $.trim($('#lastname').val()).length ? $('#lastname').attr('name') + ':  ' + $('#lastname').val() + '\n' : '';
        var fld_3 = $.trim($('#street_number').val()).length ? $('#street_number').attr('name') + ':  ' + $('#street_number').val() + '\n' : '';
        var hold_all_fields = fld_1 + fld_2 + fld_3;
        mytextareaFld.val(hold_all_fields);
    }
    

    http://jsfiddle.net/6JHRT/4/

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

Sidebar

Related Questions

I am really confused about this.I have set the background color of the whole
I`m really confused here about this weird behavior! The thing is, I have a
I'm really confused because i have the following case: Class Game extends CI_Model{ $this->load->model('user');
I am really confused about object relationships! I have two classes Person and Address.
I have really no idea why I'm asking this as this a really completely
Im new to iPhone development and I have really taken this to me. I
I really have no idea why I'm struggling with this so much. I'm scraping
I really have no idea how to go about this. So far all I
This should be an easy one, looks like I got myself too confused. I
I am trying to teach myself Python, and I have realized that the only

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.