jquery - how to prepend a textfield to a existing textfield and transfer the contents to the appended field -


i'm working on add/remove textfields have textfield , when enter add textfield, contents of current textfield should transferred textfield , current textfield should should empty. suppose have textfield textfield contains hello text, when click on "add option" , new textfield should appended top of existing textfield , contents of textfield should transferred b. how can ?
have tried below code -

$(function () {       $('.addscnt').on('click', function (event) {         event.preventdefault();         var row = $(this).closest('.row');         var div_id = parseint($(row).find('input:text').first().attr('id').split('_id_')[1])||0;         var div_name= $(row).find('input:text').first().attr('id');         var div_value= $(row).find('input:text').last().val();       });      function createinput(i,vv,name) {          var p = $('<p />'),             label = $('<label />', {                 'for': (name) +             }),             input = $('<input />', {                 type: 'text',                 'class': 'cnt',                 size: 20,                 name: (name) +i,                 id: (name) +i,                 value: vv,                 placeholder: 'input value'             }),             anchor = $('<a />', {                 href: '#',                 id: 'remscnt' + i,                 text: 'remove',                 on: {                     click: function () {                         $(this).closest('p').remove();                     }                 }             });          return p.append(label.append(input), anchor);     }      $("form").submit(function(){         var values = [];         $.each( $( '#welcome_notes input[id^=ivrgroupzbase_grpzwelcomenotes]' ).serializearray(), function ( _, item ) {             values.push( item.value );         } );          var json = json.stringify( { "datalist": values});         // posting here instead of console.log call         alert( json );         $("#ivrgroupzbase_grpzwelcomenotes").val(json);      });   }); 

fiddle

you can using below jquery :

$('.addscnt').on('click', function (event) {             event.preventdefault();             var row = $(this).closest('.row');             var input = $(row).find('input:text');             // read input value             var value = $(input).val();             // make input empty             $(input).val('');             // other parent row             var otherrow = $(row).siblings()[0];             // find input in other row , put value             var otherinput = $(otherrow).find('input:text');             $(otherinput).val($(otherinput).val()+value);         }); 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -