0

the input check box code:

<li class="odd"><input type="checkbox"  class="forminput" name="VD10" checked="checked" value="http://test1.com">
<a href="#">example 1</a></li>

<li class="even><input type="checkbox"  class="forminput" name="VD11" checked="checked" value="http://test2.com">
<a href="#">example 1</a></li>

<li class="odd"><input type="checkbox"  class="forminput" name="VD12" checked="checked" value="http://test3.com">
<a href="#">example 1</a></li>........

the button code:

<li>
<input type="checkbox" id="checkall" name="checkall" checked="checked"> 
<label for="checkall">check all</label>
<input type="button" value="copy the checked link" class="button">
</li>

now, i want to do when click the copy the checked link button. it will copy the checked input value to the clipboard? how do i do?

2
  • If only one link should be checked, you should be using radio buttons, not check boxes. If more than one can be checked, which one do you want copied? Commented Jun 15, 2011 at 6:32
  • the number of links will be copied which are optionally.as there may be one or more check boxes be checked Commented Jun 15, 2011 at 6:36

3 Answers 3

3

Try this,

$(".button").click( function () {
           var selectedCheckboxValue = "";
          $('input.forminput:checked').each(function() {

                  selectedCheckboxValue += $(this).val() + ", ";

          });
          alert(selectedCheckboxValue);
   });

click here see the working demo. http://jsfiddle.net/t5TKm/

Sign up to request clarification or add additional context in comments.

4 Comments

i want to output the result one by one. namely. the value shows as line by line. and no sign , after it? how do i do?
if i delete the "," comma, when i checked two box. the output only have one result. not two results. why?
Just use selectedCheckboxValue += $(this).val() + "\n"; instead of selectedCheckboxValue += $(this).val() + ", "; - That will give you the output line by line
Use zeroclipboard this to capture the output in the clipboard works on all platform.
0

You can't copy to the clipboard without flash, silverlight, or some other rich-client plugin.

But, here is the answer to that question: How do I copy to the clipboard in JavaScript?

And: How to retrieve checkboxes values in jQuery

1 Comment

The two links in my answer address that situation.
0

You can use the document.getElementByTag('VD10').checked to check if the checkbox is checked or not

1 Comment

Only IE provides functionality to Copy to clipboard in windows, for rest you need flash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.