how to Select and copy text at single click ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandyyyy35
    New Member
    • May 2013
    • 21

    how to Select and copy text at single click ?

    Code:
    <html>
    <title>JavaScript: Select All</title>
    <body>
    <center>
      <form>
        <textarea name="text_area" rows="10" cols="80">
          blah blah blah blah blah blah blah 
        </textarea>
      <br>
      <input type="button" value="Highlight Text" onClick="javascript:this.form.text_area.focus();this.form.text_area.select();">
      </form>
    </center>
    </body>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    when you click into the textarea or when you click the button?

    Comment

    • sandyyyy35
      New Member
      • May 2013
      • 21

      #3
      when i click button. both hit at one time select and copy.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        var text = this.form.text_ area.value

        Comment

        • sandyyyy35
          New Member
          • May 2013
          • 21

          #5
          ok, so after applying this code, just text is selecting but not copying on clipboard.

          Any new suggestions ??

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            ah, you want to copy it to the clipboard. you should have mentioned that.

            Comment

            • sandyyyy35
              New Member
              • May 2013
              • 21

              #7
              opps, sorry... please provide me the code.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                there is not "that one code". there are various solutions that have different constraints. best search for "javascript clipboard", there you find lots of how-tos and maybe the one best suited for your need.

                Comment

                • hemal8888
                  New Member
                  • Mar 2013
                  • 9

                  #9
                  try this one

                  Code:
                  <SCRIPT LANGUAGE="JavaScript">
                  <SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink">
                  This text will be copied onto the clipboard when you click the button below. Try it!
                  </SPAN>
                  
                  <TEXTAREA ID="holdtext" STYLE="display:none;">
                  </TEXTAREA>
                  <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> 
                  
                  function ClipBoard()
                  {
                  holdtext.innerText = copytext.innerText;
                  Copied = holdtext.createTextRange();
                  Copied.execCommand("Copy");
                  }
                  
                  </SCRIPT>

                  Comment

                  Working...