?
Solved

jquery send/remove checkbox values to/from textarea field onclick

Posted on 2013-12-29
3
Medium Priority
?
852 Views
Last Modified: 2013-12-29
Using jquery - how can I check my various checkboxes, have the checked value go to a textarea field - this field will be hidden on the actual form.  of course, if the field is uncheck, then that value should be removed from the textarea field.

here is a cleaned up fiddle as an example:
http://jsfiddle.net/justmelat/75nxA/

Open in new window


if I check banana, orange and peach, -->banana, orange, peach should appear in the text field. if I uncheck orange then banana, peach should appear
0
Comment
Question by:quikwallace
[X]
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
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 1600 total points
ID: 39744802
Test page : http://jsfiddle.net/75nxA/2/
$('.fruits').change(function(e){
    var fruits = [];
    $(".fruits:checked").each(function() {
        var name = $(this).attr("name"); // fruit1 or fruit2 or fruit3 or fruit4 or fruit5
        var value = $(this).val(); // YOU DID NOT SET THEM !!!!
        var nearText = $(this).get(0).nextSibling.nodeValue; // Banana or Cherry or Strawberry or Orange or Peach
        fruits.push( nearText );
    });
    $("textarea[name=holdfruites]").val(fruits.join(","));
});

Open in new window

0
 

Author Comment

by:quikwallace
ID: 39744810
Wow that is nice.  Thank you!!!!
0
 

Author Closing Comment

by:quikwallace
ID: 39744813
Great, very, extremely complete response!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses

752 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