user1839308
user1839308

Reputation: 119

copy to clipboard using getElementbyID not working

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>

Upvotes: 0

Views: 1375

Answers (1)

Jonathan
Jonathan

Reputation: 5018

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

Upvotes: 2

Related Questions