Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

How to split words into | (pipe sign)

Hi there

Hope all is ok.

I have this code:

    function fun_get() {
        var ele = jQuery('input[name=CheckboxStatus]:checked').map(function () {
            return this.value;
        }).get().join()
      
        return ele;
    }

Open in new window


and I have a checkbox when I select for example the checkbox "blue" and running the function above I get:

blue

HOWEVER, if I check 2 or more checkboxes I get

blue,red,green

can someone please help me with the JS code, What I want is if I select 1 option it should be for example (as seen below):

blue

If I select more then 1 it should be

blue|red|green

as you can see it places a pipe sign IF there are more then 1 selected, also as you can see there is NOT a pipe sign at the end of the string.

hope someone can come back to me.

thanks
0
mousemat24
Asked:
mousemat24
  • 5
  • 3
1 Solution
 
plusone3055Commented:
a
0
 
mousemat24Author Commented:
it is part of jquery
0
 
mousemat24Author Commented:
or I can use this, but it still creates the same problem

    function getCheckBoxValues(checkboxName) {
        var checkboxVals = [];
        $('input:checkbox[name=CheckboxStatus]:checked').each(function (index) {
            checkboxVals.push($(this).val());            
        })          
    }

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
plusone3055Commented:
the separation is happening inside the JQuery script with the Comma

not with in the code you provided.

search through the jQuery script (particulalrly the join function)  and find the Comma separator and change the  "," to a "|" and you'll be good to go  :)
0
 
mousemat24Author Commented:
problem is I cant really do that, because some other part of the site uses that
0
 
plusone3055Commented:
never fear
duplicate the join function in the Jquery and call it Join2 and use the join2 function where you need it.
0
 
mousemat24Author Commented:
you are correct, all I had to do was


join("|")
0
 
mousemat24Author Commented:
thanks for the tip
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now