Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unselect selected text

    function copyit() {
    if (bBool) {
    tempstore=copiedtext
    document.execCommand("Copy")
    copiedtext=window.clipboardData.getData("Text");
    bBool=false;
    }
    }
    How to unselect the text after the text was copied?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Not sure if this is any good

    PHP Code:
    <script type="text/javascript">
    <!--

    moz=document.getElementById&&!document.all
    function unselect_selection(){
    if(!
    moz){
    oTextRange document.selection.createRange()
    oTextRange.expand("word")
    oTextRange.execCommand("unselect")
    }
    else{
    oTextRange window.getSelection()
    oTextRange.collapseToStart()
    }
    }
    //-->
    </script> 

    <P>Highlight some text then click <a href="#null" onclick= "unselect_selection()"><b>Unselect Selection</b></a> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    10x dude...

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,455
    Thanks
    0
    Thanked 632 Times in 622 Posts
    That code will crash Opera. Don't use document.all it has nothing whatever to do with what you need to test for. Test if the feature you need to use is supported not some other irrelevant field.

    The only valid use for document.all is:

    if (document.all && !document.getElementById) alert('You are one of the two people still using IE4, isn\'t it time you upgraded');

    You might use:

    moz = !window.execCommand;

    which at least tests properly for if the browser isn't Internet Exploder.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to unselect text.. just do this:

    function unselect(fieldName){
    /*
    fieldName contains selected text.
    to unselect, just remove the text then write it back:
    */
    var myfield = document.forms[0].fieldName;
    var temp = myfield.value;
    myfield.value = "";
    myfield.value = temp;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •