PDA

View Full Version : Split option value display onto label



heyweed
08-15-2011, 07:50 AM
Hi

How to split the selected multiple box here is the code:

if selectedArray.options[i].selected >0
all items behind is tag with a comma but i do not want the last item to have a comma.



//id for label
var txtSelectedValuesObj = document.getElementById('txtSelectedValues');
var selectedArray = new Array();
var selObj = document.getElementById('Part'); //id for multiple select box
var i;
var count = 0;
var strSelectedParts = "";

selectedArray = split(selObj.value, ",");

for (i=0; i<selectedArray.options.length; i++)
{
if (selectedArray.options[i].selected) {
selectedArray[count] = selectedArray.options[i].value;
strSelectedParts += selectedArray.options[i].value;
}
count++;
}
txtSelectedValuesObj.value = strSelectedParts;

jscheuer1
08-15-2011, 01:31 PM
We would really need to see the markup that goes with this. But the first thing I'd try is changing:


selectedArray = split(selObj.value, ",");

to:


selectedArray = (selObj.value).split(",");

If that doesn't work, you can try adding the highlighted here:


txtSelectedValuesObj.value = strSelectedParts.replace(/, *$/, '');

If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.