Jump to content

Alert Box in Report Datapage


Recommended Posts

Hi, I have been searching for how to use the alert box. But I mostly found those for submission forms. Hence this one worked for me. But I would like it really to work first in the listing before the submission form. How could you revise this alert to work as a simple message in a report datapage. Thanks in advance.
 

<script type="text/javascript">
 function check()
 {
var countr = document.getElementById("xip_Country")

if ((countr !="COUNTRY1")&&(countr !="COUNTRY2")) 
{
alert("sample message");
return false;
}
};
 document.getElementById("caspioform").onsubmit=check;
</script>

Link to comment
Share on other sites

@Tubby Thanks for replying! I got it already to work. I started from the simplest code and it worked :) Simplicity is key
 

<script>

var countr = '[@authfield:Country]';

if ((countr !="COUNTRY1")&&(countr !="COUNTRY2")) {
alert("MESSAGE");
};
</script>

However, now that the Caspio directory in Version 37.0 can already use Yes/NO field I am looking for a way that a YES is checked when this alert box is okay-ed for the first time or at least for the 3rd time, or the alert will be a nuisance. I would appreciate your help.

 

Link to comment
Share on other sites

17 hours ago, bookish said:

@Tubby Thanks for replying! I got it already to work. I started from the simplest code and it worked :) Simplicity is key
 

<script>

var countr = '[@authfield:Country]';

if ((countr !="COUNTRY1")&&(countr !="COUNTRY2")) {
alert("MESSAGE");
};
</script>

However, now that the Caspio directory in Version 37.0 can already use Yes/NO field I am looking for a way that a YES is checked when this alert box is okay-ed for the first time or at least for the 3rd time, or the alert will be a nuisance. I would appreciate your help.

 

Ah I guess it is to check whether the user is assigned to that country that they are viewing. Anyways, try declaring a counter for your alert box if you want to prevent it from firing after nth number of times:

Something like this maybe:

<script>

var countr = '[@authfield:Country]';
var i = 0;

if ((countr !="COUNTRY1")&&(countr !="COUNTRY2")&&(i < 4)) {
alert("MESSAGE");
i++;
};
</script>

Link to comment
Share on other sites

Just for the record, the problem could be with the value of "i" not being persistent across page loads. So consulting chat.openai and I got this script which worked. Hope it helps anyone

<script>
var countr = '[@authfield:Country]';
var i = parseInt(getCookie("alertCounter")) || 0; // Get the value of i from the cookie, or initialize to 0 if it's not set

if (countr !== "COUNTRYA" && countr !== "COUNTRYB" && i < 4) {
  i++;
  setCookie("alertCounter", i, 365); // Set the value of i in the cookie for 1 year
  alert("MY MESSAGE");
}

function setCookie(name, value, days) {
  var expires = "";
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    expires = "; expires=" + date.toUTCString();
  }
  document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}

function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
</script>
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...