As I wrote in the question title I was just wondering if a block of ampscript & ssjs combined code can be execute on change via checkbox check/uncheck?
<input name="TopicID" type="checkbox" onchange="sub-unsub" value="Newsletter"
%%[ IF @TopicID == "Koronavirus" THEN ]%% checked %%[ ENDIF ]%%> Novica1</label>
and I would like to call this code onChange()
%%[
SET @sub = "EmailAddress"
SET @email = "EmailAddress"
SET @Listid = "ListID"
SET @ListStatus = "Active"
SET @listemailexist = Lookup("_ListSubscribers","EmailAddress","ListID", @Listid,"EmailAddress", @email,"Status", @ListStatus)
]%%
%%[if @listemailexist == @email AND @ListStatus == "Active" Then]%%
subscriber already exist
%%[ELSE]%%
<script runat="server">
Platform.Load("core","1.1.5");
var prox = new Script.Util.WSProxy();
var options = {SaveOptions: [{'PropertyName': '*', SaveAction: 'UpdateAdd'}]};
//getting values from AMPSCRIPT variables to SSJS variables
var email = Variable.GetValue("@email");
var subscriberkey = Variable.GetValue("@sub");
function AddToSub(obj) {
var props = {
SubscriberKey: subscriberkey,
EmailAddress: email,
Lists: [{
ID: obj.listID,
Status: 'Active' // to unsub = "Unsubscribed" to subscribe = "Active"
}]
};
var data = prox.updateItem("Subscriber", props, options);
return data.Results[0].StatusCode;
}
var myPubLists = [
{mid:'MID', listID:'ListID'}
];
for (var i=0; i<myPubLists.length; i++) {
var result = AddToSub(myPubLists[i]);
Write("Subscriber has been added to the publication list");
}
</script>
%%[ENDIF]%%
Has anyone tried this before.
Tnx.