Results 1 to 2 of 2

Thread: Split option value display onto label

  1. #1
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Split option value display onto label

    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.

    Code:
    //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;

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    We would really need to see the markup that goes with this. But the first thing I'd try is changing:

    Code:
    selectedArray = split(selObj.value, ",");
    to:

    Code:
    selectedArray = (selObj.value).split(",");
    If that doesn't work, you can try adding the highlighted here:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •