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?

runeveryday
  • 2,751
  • 4
  • 30
  • 44
  • 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? – Alnitak Jun 15 '11 at 06:32
  • the number of links will be copied which are optionally.as there may be one or more check boxes be checked – runeveryday Jun 15 '11 at 06:36

3 Answers3

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/

Sahal
  • 4,046
  • 15
  • 42
  • 68
  • 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? – runeveryday Jun 15 '11 at 07:24
  • if i delete the "," comma, when i checked two box. the output only have one result. not two results. why? – runeveryday Jun 15 '11 at 07:28
  • 1
    Just use `selectedCheckboxValue += $(this).val() + "\n";` instead of `selectedCheckboxValue += $(this).val() + ", ";` - That will give you the output line by line – Rakesh Sankar Jun 15 '11 at 07:29
  • Use [zeroclipboard](http://code.google.com/p/zeroclipboard/) this to capture the output in the clipboard works on all platform. – Rakesh Sankar Jun 15 '11 at 07:38
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

Community
  • 1
  • 1
Steve
  • 31,144
  • 19
  • 99
  • 122
0

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

Balanivash
  • 6,709
  • 9
  • 32
  • 48