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 10 of 10
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    HELP! I can't figure this one out!


    Hi All,
    I have an app here that uses .xsl sheets for certain lookup screens. these screens have buttons that pull up tables of data from MSSQL. what I am looking to do is have a button next to each row of data, set up so that when the button is pressed it copies that row of data to the clipboard. Here is my dillema:
    If the button for 'recent sales' is pressed, and the table return is a single row, then my 'copy' function and button works fine. If, however, the table return is multiple rows of data, then the button appears but blows up when I click it. I know this is because each button/function needs unique ID's, but I can't figure out how to (1) get each row of data a sequence#, and (2) how to make that # increment the function ID's.
    here is the code for the 'copy' function:
    Code:
    <!-- set the clipboard parameters for the copy button -->
    function ClipBoard()
    {
    holdtext.innerText=copytext.innerText;
    Copied=holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    
    </script>
    And here is the .xsl for the 'recent sales' selection:
    Code:
    <!--                Recent Sales                                            -->
    
            <TD align="center" width="20%">
              <INPUT class="formbutt" type="button" 
                     id="SalesHistBtn" name="submit">
                <xsl:attribute name="value">
                  <xsl:value-of select="/zoom/query2/@query_label"/>
                </xsl:attribute>
    
                <xsl:choose>
                  <!-- If data records are on file -->
                  <xsl:when test="/zoom/query2/node()">
                    <xsl:attribute name="onclick">
                      ShowDivData(SalesHistBtn, SalesHistDiv)
                    </xsl:attribute>
                    <xsl:attribute name="style">
                      width: 98%;
                    </xsl:attribute>
                  </xsl:when>
    
                  <!-- Otherwise button not active -->
                  <xsl:otherwise>
                    <xsl:attribute name="style">
                      width: 98%; color: inactivecaption; background-color: buttonface"
                    </xsl:attribute>
                  </xsl:otherwise>
                </xsl:choose>
    
              </INPUT> 
            </TD>
    
    
    <!-- ====================================================================== -->
    <!-- Section D) Division for Recent Sales                         (Query 2) -->
    <!-- ====================================================================== -->
    
      <DIV id="SalesHistDiv" style="display: none">
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="2" CELLPADDING="3" BGCOLOR="#637994">
          <TR><TD>
            <FONT COLOR="#ffffff" SIZE="2"><B>
                  <xsl:value-of select="/zoom/query2/@query_label"/>:
            </B></FONT>
          </TD></TR>
        </TABLE>
    
        <TABLE WIDTH="98%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="3" BGCOLOR="#858573">
          <TR ALIGN="CENTER">
    
            <!-- For each field label -->
            <xsl:for-each select="/zoom/query2[position()=1]/*">
              <TD BGCOLOR="#B5B5A6" STYLE="FONT-SIZE: 8pt; HEIGHT: 8px;" WIDTH="1%">
                <xsl:attribute name="NOWRAP"/>
                <SMALL><xsl:value-of select="@display_label"/></SMALL>
              </TD>
            </xsl:for-each>
            <TD WIDTH="1%" BGCOLOR="#B5B5A6">
              Copy Info
            </TD>
          </TR>
    
          <!-- For each field value -->
          <xsl:for-each select="/zoom/query2">
            <TR ALIGN="CENTER">
              <xsl:for-each select="./*">
               		    <TD BGCOLOR="White" STYLE="height: 8px; FONT-SIZE: 8pt;" WIDTH="1%">
                  <SMALL><xsl:value-of select="."/></SMALL>
                </TD>
              </xsl:for-each>
              <!-- build the copy button and tie it to the clipboard-->
    		  <TD WIDTH="1%" BGCOLOR="White">
              
    
                   <SPAN ID="copytext" STYLE="display:none;" >
    			   <!-- enter the data to copy below-->
    			   <xsl:value-of select="./TKT_NO"/>
    			   <!--enter the data to copy above-->
    			   </SPAN>
    			   <TEXTAREA ID="holdtext" STYLE="display:none;" >
    			   </TEXTAREA>
    			 <BUTTON onClick="ClipBoard();">copy</BUTTON>
    			  
              </TD>
            </TR>
          </xsl:for-each>
        </TABLE>
    
      </DIV>
      <!-- End Section D and Query 2 processing -->
    The fields we want to copy will fall inside the <SPAN> above.
    Can anyone help??
    Thanks in advance,
    Andy

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Let's see...

    If your buttons always follow the textareas, get rid of the id on the textarea, and pass an argument to the function from the event handler:

    <TEXTAREA STYLE="display:none;" >
    </TEXTAREA>
    <BUTTON onClick="ClipBoard(previousSibling);">copy</BUTTON>

    function ClipBoard(holdtext)
    {
    // leave as is...
    }



    Edit: You may also need to do the same for the span "copytext"; if so, just add another argument...
    Last edited by codegoboom; 11-13-2004 at 06:42 PM.
    *this message will self destruct in n-seconds*

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    HEY!
    Close, but not quite. I did what you suggested, and now the button doesn't blow up the script anymore, but the only thing it puts on the clipboard is 'undefined'....

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't really know what's happening all together, but this works for me:

    Code:
    <body>
    <script type="text/javascript">
    function ClipBoard(holdtext)
    {
    holdtext.innerText=copytext.innerText;
    Copied=holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    </script>
    <SPAN ID="copytext" STYLE="display:none;" >blah</SPAN>
    <TEXTAREA STYLE="display:none;"></TEXTAREA>
    <BUTTON onClick="ClipBoard(previousSibling);">copy</BUTTON>
    </body>
    Do you get undefined with that example, as well?
    Last edited by codegoboom; 11-13-2004 at 07:00 PM.
    *this message will self destruct in n-seconds*

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok,
    I think I see the problem. The text that is selected is actually nested between the <SPAN></SPAN> coding, and not the <TEXT></TEXT>.
    The textarea is a window that shows what has been copied to the clipboard from the span. Since the button is calling (prevoiusSibling), is that the problem? If so, what is the proper fix?
    Thanks again!!

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You may need to reference the span(s) via argument, rather than id...
    *this message will self destruct in n-seconds*

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    oooookay.....
    hate to show that I'm an idiot, but just how do I do that?

  • #8
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Apparently, textarea doesn't expose the span as a previousSibling, so you may need to enclose the three elements in a div to allow for reference by position:

    Code:
    <body>
    <script type="text/javascript">
    function ClipBoard(holdtext, copytext)
    {
    holdtext.innerText=copytext.innerText;
    Copied=holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    </script>
    <div>
    <SPAN STYLE="display:none;">blah</SPAN>
    <TEXTAREA STYLE="display:none;"></TEXTAREA>
    <BUTTON onClick="ClipBoard(previousSibling, parentElement.getElementsByTagName('SPAN')[0]);">copy</BUTTON>
    <div>
    </body>
    You can change that to parentElement.firstChild, if that's always going to be the position of the span...
    Last edited by codegoboom; 11-13-2004 at 07:30 PM.
    *this message will self destruct in n-seconds*

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    GOT IT!!
    When I first put it in it blew up BAAAADDD!!!
    But then I realized that the 'recent sales' section is a DIV all by itself, so I removed the DIV tags from the stuff you sent, and
    TAADAA!!
    Thank you so much. By The way, That's a cool username!
    Andy

  • #10
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad to hear that you were able to defuse the snippet...
    ...turned out to be the blue wire!
    Last edited by codegoboom; 11-13-2004 at 08:28 PM. Reason: debriefing
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

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