javascript - Remove comma at the begining at the of new results output -


i use script copy values span class values in form. when copy more 1 script adds comma @ beginning of returned results. not sure problem is.

<script> var results = [];  $('input[name="clickme"]').change(function () {     var id = $(this).attr('class');     $('table#' + id).toggleclass('selected');      var proc_code = $('table#' + id + ' .proc_code').text();     var medicare = $('table#' + id + ' .medicare').text();     var status = $('table#' + id + ' .status').text();     var ata_id = $('table#' + id + ' .ata_id').text();     var sys_app = $('table#' + id + ' .sys_app').text();     var submitter = $('table#' + id + ' .submitter').text();     var email = $('table#' + id + ' .email').text();     var add_cpt = $('table#' + id + ' .add_cpt').text();     var change = $('table#' + id + ' .change').text();      if ($('input.' + id).is(':checked')) {         results.push(proc_code + '\n' + sys_app + '\n' + change + '\n\n');         if ('console' in window) console.log(results);         $('#results').val(results);     } else {         results.pop(proc_code + '\n' + sys_app + '\n' + change + '\n\n');         $('#results').val(results);     }  }); </script> 

var results = []; 

you have declared result array.

results.push(proc_code + '\n' + sys_app + '\n' + change + '\n\n');   

you pushing elements array

$('#results').val(results); 

results array converted comma seperated string , put #results element

to solve below i.e.

var result=''; //using string 

... change

 results.push(proc_code + '\n' + sys_app + '\n' + change + '\n\n');   

to

results= results + ' '+ proc_code + '\n' + sys_app + '\n' + change + '\n\n'; 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -