This code generates a comma separated string to provide a list of ids to the query string of another page, but there is an extra comma at the end of the string. How can I remove or avoid that extra comma?
<script type="text/javascript"> $(document).ready(function() { $('td.title_listing :checkbox').change(function() { $('#cbSelectAll').attr('checked', false); }); }); function CotactSelected() { var n = $("td.title_listing input:checked"); alert(n.length); var s = ""; n.each(function() { s += $(this).val() + ","; }); window.location = "/D_ContactSeller.aspx?property=" + s; alert(s); } </script>
Use Array.join
var s = ""; n.each(function() { s += $(this).val() + ","; });
becomes:
var a = []; n.each(function() { a.push($(this).val()); }); var s = a.join(', ');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With