Solved

How to split words into | (pipe sign)

Posted on 2014-04-25
8
354 Views
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;
        }).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
Comment
Question by:mousemat24
  • 5
  • 3
8 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 40022677
a
0
 

Author Comment

by:mousemat24
ID: 40022683
it is part of jquery
0
 

Author Comment

by:mousemat24
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) {
            checkboxVals.push($(this).val());            
        })          
    }

Open in new window

0
 
LVL 22

Accepted Solution

by:
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  :)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Expert Comment

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

Author Closing Comment

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


join("|")
0
 

Author Comment

by:mousemat24
ID: 40022705
thanks for the tip
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now