bookish Posted April 8 Report Share Posted April 8 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> Quote Link to comment Share on other sites More sharing options...
Tubby Posted April 8 Report Share Posted April 8 @bookish what is the intended use of the alert box for the listing(list datapage I assume)? Like when should it pop up? Are there conditions? Quote Link to comment Share on other sites More sharing options...
bookish Posted April 14 Author Report Share Posted April 14 @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. Quote Link to comment Share on other sites More sharing options...
Tubby Posted April 14 Report Share Posted April 14 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> bookish 1 Quote Link to comment Share on other sites More sharing options...
bookish Posted April 15 Author Report Share Posted April 15 Thanks @Tubby for the effort. It was not working for me. So I used console log and it keeps showing 1 for the value of i. Quote Link to comment Share on other sites More sharing options...
bookish Posted April 15 Author Report Share Posted April 15 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.