Hi Guys!

This should be a very easy question, I know how to do it in PHP, but how can I do it in JavaScript...

I have a Javascript function which loops through a list of checkboxes and creates a string of the values of the selected checkboxes. However, it always adds an extra comma on the end of the string. How can I stop it adding the extra comma once it reaches the end of the loop?

Code JavaScript:
function save_industries(){
	var namelist = "";
	with(document.select_industries) {
		for(var i = 0; i < industry.length; i++){
			if(industry[i].checked) {
				namelist += industry[i].value + ",";
	if(namelist == "") {
		alert("Please select at least 1 industry.");
	} else {
		opener.document.searchform.industry.value = namelist;
		opener.document.getElementById("industry_list").innerHTML = "<span class=\"info\"><a href=\"#\" onclick=\"javascript:select_industries('" + namelist + "')\">Industries selected, click to edit</a></span>";