...

View Full Version : HELP! I can't figure this one out!



steamngn
11-13-2004, 05:01 PM
:confused:
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:

<!-- 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:

<!-- 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

codegoboom
11-13-2004, 06:38 PM
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...
}


You may also need to do the same for the span "copytext"; if so, just add another argument...

steamngn
11-13-2004, 06:48 PM
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'.... :eek:

codegoboom
11-13-2004, 06:55 PM
I can't really know what's happening all together, but this works for me:



<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?

steamngn
11-13-2004, 06:59 PM
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!!

codegoboom
11-13-2004, 07:06 PM
You may need to reference the span(s) via argument, rather than id...

steamngn
11-13-2004, 07:09 PM
oooookay.....
hate to show that I'm an idiot, but just how do I do that?

codegoboom
11-13-2004, 07:27 PM
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:


<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...

steamngn
11-13-2004, 07:55 PM
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 :thumbsup:

codegoboom
11-13-2004, 08:25 PM
Glad to hear that you were able to defuse the snippet... ;)
...turned out to be the blue wire! :eek:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum