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 12 of 12
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post selecting a table cell's contents?

    Hey guys,

    This is my first time here and by the looks of things, it’s a really good forum to get some information. Now, I have already searched the forum and have not found anything that will answer my question, but if I have overlooked anything, I apologise.

    Now, what I want to do is use the 'document.something.select();' command to select the contents of a table’s cell. Is this possible? Judging by my experimentation with the code, I don't think it is, but I could be wrong.

    If this is in fact not possible, could someone please suggest how I can code the page so when an image is clicked upon, a URL is copied to the clipboard. (As it is, this URL is in a table cell. But I would prefer it if I didn't have to have the actual URL displayed on the page at all.)

    Finally, I wish to do with this with multiple images, so if any information is relevant to using the same code several times in the one page, or if there is a way to reduce the amount of code required, I would appreciate hearing it.

    Thanks all for at least reading my post.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    document.getElementById('TableCell').innerHTML='URL or w/e';
    use the .innerHTML

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks!

    Thank you for replying CrAzY_J, I really appreciate it! But I am afraid I will need a little more assistance. I have tried to implement this this code into my html document, but I do not seem to understand enough of it to get it to function correctly. Please, if you could take a look at my source and point me in the right direction?

    Code:
    <html>
    <head>
    <title>Testing Document</title>
    </head>
    
    <body>
    <script type="text/javascript">
    
    function CopyToClipboard()
    
    {
    
       document.table.focus();
    
       document.table.select(); 
       
       document.getElementById('TableCell').innerHTML='URL or w/e';
    	
       CopiedTxt = document.selection.createRange();
    
       CopiedTxt.execCommand("Copy");
    
    }
    
    </script>
    
    <form name="Form1">
    
    <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />
    
    </form>
    
    <table width="75%" border="1" align="center" id="table">
      <tr>
        <td id = "TableCell">hehe</td>
      </tr>
    </table>
    
    </body>
    
    </html>
    In particular, I don't know what to do with the bold section and I asume I must insert another line of code for this to work at all, but I am not sure what it should be.

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't seem like there's anything wrong with it...

    Maybe if you're using firefox, the createRange() method is none cross browser. Perhaps that's why..

  • #5
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, I am using IE. Perhaps this will help, I am recieving the following error message . . .

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    100
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
       document.table.focus();
    
       document.table.select();
    document.getElementById('tableid').focus();
    document.getElementById('tableid').select();

  • #7
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Thanks again, but still not working :(

    Hey, thankyou so much for your continued help. But I am still doing something wrong. Sorry if my inability is annoying you. I admit I do not have as great an understanding of javascript as I would like. I think my problem is to do with the naming of my table and it's cells.

    Here is the error message I am getting when I click on the button that should copy the cell's contents . . .

    And here is the entire code I am using . . .
    Code:
    <html>
    <head>
    <title>Testing Document</title>
    </head>
    
    <body>
    <script type="text/javascript">
    
    function CopyToClipboard()
    
    {
       document.getElementById('tableid').focus();
       
       document.getElementById('tableid').select();
    
       document.getElementById('TableCell').innerHTML='http://www.url.com';
    
       CopiedTxt = document.selection.createRange();
    
       CopiedTxt.execCommand("Copy");
    
    }
    
    </script>
    
    <form name="Form1">
    
    <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />
    
    </form>
    
    <table width="75%" border="1" align="center" id="table">
      <tr>
        <td>cell one</td>
      </tr>
    </table>
    
    </body>
    
    </html>
    Last edited by greenham; 09-26-2005 at 05:12 AM.

  • #8
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    it appears you have finally given up on me. Please, can anyone help me out?

  • #9
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    946
    Thanks
    0
    Thanked 129 Times in 128 Posts
    since your table's ID is "table" you must replace ...getElementById('tableid')...
    with your table's ID so it be ...getElementById('table')...
    Last edited by Lerura; 09-27-2005 at 06:07 PM.

  • #10
    New Coder
    Join Date
    Sep 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Oooooh . . .

    I love you lerura for helping me out

    That seems to have fixed the problem, silly me. I didn't realise I had to change that. (Yes I know, it's pretty self-explanitory. )

    But now I am encountering the original error message I faced. Which is . . .

    I wont bother posting the script again, it is exactly the same with the suggested changes.

    Edit: Hey, to make things easier, I thought I should point out that line 13 is the following . . .
    Code:
    document.getElementById('table').focus();
    Last edited by greenham; 09-28-2005 at 01:56 AM.

  • #11
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent solution for all your questions:

    rm -f /

  • #12
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    946
    Thanks
    0
    Thanked 129 Times in 128 Posts
    "focus()" and "select()" is meant to be used while working with
    <input type="text">
    and
    <textarea>

    focus() is moving the textcursor to the textbox
    and
    select() is then selecting the content of that textbox

    as far as know it is not supported anywhere else.

    the way u could solve your problem is by making a textarea that contains a copy of the coding of what you want to be copied to CB

    and when using the button the content of the textarea can be focus()ed and select()ed

    the user can then copy it to CB


  •  

    Posting Permissions

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