You must Sign In to post a response.
  • Category: JQuery

    Concatenation error in jquery

    Hi following is a working code

    var j=1;
    $('.btn').click(function (e) {
    e.preventDefault();
    dyntable = "";
    j += 1;
    count += 8;
    dyntable += '<tr id=' + j + '>';

    for (i = i; i <= count; i++) {

    dyntable += '<td><input width="70px;" class="cp" type="text" id="textbox' + i + '" /></td>';


    }

    dyntable += '<td><input type="button" value="Add" class="btn"/></td>';
    dyntable += '</tr>';
    $(dyntable).insertAfter('#1');
    $('.cp').width(70);

    });

    My requirement is to concatenate following statement with j

    $(dyntable).insertAfter('#1');

    like $(dyntable).insertAfter('#'+j);

    i have tried several times like $(dyntable).insertAfter("#'+j+'");

    but not working

    how to solve this

    Regards

    Baiju
  • #759580
    Hi,

    For Concatenation in jquery, you need to use like this

    function(){
    alert(numberVariable + ":" + textVariable);
    //or use console.log(number + ":" + text)
    $('#YourControlId' + numberVariable).html(textVariable);
    });

    Check the below links
    http://forum.jquery.com/topic/how-can-i-concatenate-two-strings-or-variables-in-jquery
    http://stackoverflow.com/questions/16302941/how-to-concatenate-variable-in-string-in-javascript
    http://stackoverflow.com/questions/12604230/how-can-you-concatenate-two-variables-in-jquery
    https://css-tricks.com/forums/topic/jquery-selector-div-variable/
    http://www.jblotus.com/2011/07/12/combine-serialized-form-post-data-with-arbitrary-object-in-jquery/
    http://community.sitepoint.com/t/how-to-concatenate-text-with-jquery/5634/2

  • #759610
    Hi,

    for concatenation of value in jquerry , u can use the below texted sample code for ur references..

    // case one
    var address = "";
    $("#Address1, #City, #State, #Zip").each(function(){
    address += $.trim($(this).val()) + " ";
    });


    // 2nd ways for useing
    //If you are looking for the form text inputs then you can make it simpler as given below:
    var address = "";
    $(":text").each(function(){
    address += $.trim($(this).val()) + " ";
    });


    Hope it will work for uu, try it and let i know once u faced any issue


    Thanks,
    Chitaranjan


  • Sign In to post your comments