0

I'm using this copy to clipboard script to copy values that are returned to a table row. It works fine when I use an actual field but not when I'm trying copy values from what gets entered into the row. Why wouldn't it just grab the values like a field since I'm using getElementByID.... Obviously no expert but in theory it seems like it should work

        <script type="text/javascript"><!--
    // input field descriptions
    var desc = new Array();
    desc['PROC_CODE'] = 'Procedure Code';
    desc['STATUS'] = 'Status';
    function CopyFields(){
        var copytext = '';
        for(var i = 0; i < arguments.length; i++){
            copytext += desc[arguments[i]] + ': ' + document.getElementById(arguments[i]).value + '\n';
        }
        var tempstore = document.getElementById(arguments[0]).value;
        document.getElementById(arguments[0]).value = copytext;
        document.getElementById(arguments[0]).focus();
        document.getElementById(arguments[0]).select();
        document.execCommand('Copy');
        document.getElementById(arguments[0]).value = tempstore;
    }
    --></script>
    </head>
    <body>


      <table width="100%" border="0" cellpadding="5" cellspacing="1">
        <tr bgcolor="#F0F0F0"> 
          <td colspan="5" align="center" class="th2">1) Procedure Code Record</td>
        </tr>
         <tr bgcolor="#F0F0F0">
          <td width="12%" align="right" bgcolor="#CCCCCC" class="tdFieldHeadingsR1">
            Procedure Code </td>
          <td width="1%" align="right" bgcolor="#FFFFFF" class="tdFieldHeadingsR1">&nbsp;</td>
          <td width="55%" bgcolor="#FFFFFF" class="tLBL1l" id="PROC_CODE" name="PROC_CODE">&nbsp;
            </td>

        </tr>

        <tr bgcolor="#F0F0F0">
          <td width="12%" align="right" bgcolor="#CCCCCC" class="tdFieldHeadingsR1">
            STATUS </td>
          <td width="1%" align="right" bgcolor="#FFFFFF" class="tdFieldHeadingsR1">&nbsp;</td>
          <td width="55%" bgcolor="#FFFFFF" class="tLBL1l" id="STATUS" name="STATUS" >&nbsp;
            </td>

        </tr>

    <a href="#" onclick="CopyFields('PROC_CODE', 'STATUS');">Copy values of text fields to clipboard</a>
user1839308
  • 119
  • 1
  • 3
  • 13

1 Answers1

2

Take a look at: JavaScript, getting value of a td with id name

I think you want .innerText to get the text content, not .value

Community
  • 1
  • 1
Jonathan
  • 4,916
  • 2
  • 20
  • 37
  • You are correct .innerText is the way to go with this. Still can't seem to get it to copy though after changing the .value to .innerText. – user1839308 Apr 07 '13 at 01:48
  • Copying to clipboard via javascript only is not possible in all browsers. The workaround is to use a small flash aplpet. See: http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript – Jonathan Apr 08 '13 at 18:53