• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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