Fantastic, thank you Matthew and Marc. With some fiddling, and realizing that the "not a function" error was because I wasn't loading SPServices in JSFiddle, I have this working in my DVWP.
Below is the code I'm using,
Links from each row with test to determine if child exists or not and showing appropriate button.
-Robert
Below is the code I'm using,
Links from each row with test to determine if child exists or not and showing appropriate button.
<div class="" id="dataFeedsForSelected">
<xsl:if test="string-length($varGetOpDfID) >= 1">
<a title="" href="#" class="btnChangeDfAssoc" data-id="{$varGetOpDfID}" data-list-name="OP Data Feed" data-batch-cmd="Delete" data-op-poc="NA" data-op-prj="{$pj}" data-df-id="NA"><img alt="" src="/_layouts/images/CMSUNLINK.gif"/></a>
</xsl:if>
<xsl:if test="string-length($varGetOpDfID) < 1">
<a title="" href="#" class="btnChangeDfAssoc " data-id="NA" data-list-name="OP Data Feed" data-batch-cmd="New" data-op-poc="{$opp}" data-op-prj="{$pj}" data-df-id="{@ID}"><img alt="" src="/_layouts/images/addusergroup.gif"/></a>
</xsl:if>
</div>
The script, loaded after the <div> with the ID of dataFeedsForSelected<script type="text/javascript">
$(document).ready(function () {
$("#dataFeedsForSelected").on("click", ".btnChangeDfAssoc", function (event) {
event.preventDefault();
var $this = $(this),
data = $this.data(),
id = data.id,
listName = data.listName,
batchCmd = data.batchCmd,
opPoc = data.opPoc,
opPrj = data.opPrj,
dfId = data.dfId;
console.log(id);
console.log(listName);
console.log(batchCmd);
console.log(opPoc);
console.log(opPrj);
console.log(dfId);
if (batchCmd == "New") {
{
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: "OP Data Feed",
valuepairs: [
["OPPOC", opPoc],
["OnboardingProject", opPrj],
["DataFeed", dfId]
],
debug: true,
completefunc: refreshPage
});
}
}
else if (batchCmd == "Delete") {
{
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "Delete",
listName: listName,
ID: id,
debug: true,
completefunc: refreshPage
});
}
}
});
});
function refreshPage() {
window.location.replace('<xsl:value-of select="$thisPage"/>');
}
</script>
I hope someone else finds this helpful.-Robert