How to split words into | (pipe sign)

Posted on 2014-04-25
Last Modified: 2014-04-25
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;
        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:


HOWEVER, if I check 2 or more checkboxes I get


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):


If I select more then 1 it should be


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.

Question by:mousemat24
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 22

Expert Comment

ID: 40022677

Author Comment

ID: 40022683
it is part of jquery

Author Comment

ID: 40022688
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) {

Open in new window

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

LVL 22

Accepted Solution

plusone3055 earned 500 total points
ID: 40022692
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  :)

Author Comment

ID: 40022697
problem is I cant really do that, because some other part of the site uses that
LVL 22

Expert Comment

ID: 40022703
never fear
duplicate the join function in the Jquery and call it Join2 and use the join2 function where you need it.

Author Closing Comment

ID: 40022704
you are correct, all I had to do was


Author Comment

ID: 40022705
thanks for the tip

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP: Filling Out/Creating a PDF 29 107
How Close unsubmited attempts 10 46
replacing inline javascript with jquery 4 46
How to get text of href without any ID using Javascript 9 24
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question