Jump to content

Disable A Form


Recommended Posts

Hello bookish,

 

You can add a Header&Footer element, select the Footer element, click the Source button and enter the following JavaScript code, that will check the field:

<SCRIPT LANGUAGE="JavaScript">

function check_date()
{
var entered_value = document.getElementById("InsertRecorddate_value").value;
var entered_date = new Date(entered_value);
var entered_year = entered_date.getFullYear();

var today = new Date();
var current_year = today.getFullYear();

var allowed_years = 15;

if(current_year - entered_year < allowed_years)
   {
      alert("Incorrect Birthday.");
      return false;
   }
}

document.getElementById("caspioform").onsubmit=check_date;
</SCRIPT>

Please, insert the name of your field instead of "date_value" in the following line:

var entered_value = document.getElementById("InsertRecorddate_value").value;

You can also enter you message instead of "Incorrect Birthday." and change the value of "allowed_years".

 

I hope, it helps.

Link to comment
Share on other sites

  • 11 months later...

Hi Aurora,

 

You are right, it was not completely good code.

You can use the update code (please, enter the name of you field instead of FIELDNAME and the correct number instead of "15":

<SCRIPT LANGUAGE="JavaScript">
function check_date()
{
var field_name = "FIELDNAME";
var allowed_years = 15;

field_name = "InsertRecord" + field_name;
var entered_value = document.getElementById(field_name).value;
var entered_date = new Date(entered_value);
var entered_year = entered_date.getFullYear();
var today = new Date();
var current_year = today.getFullYear();
var denied = false;

if(current_year - entered_year <= allowed_years)
  {
   if (current_year - entered_year == allowed_years)
     {
      var entered_month = entered_date.getMonth();
      var current_month = today.getMonth();
      if (current_month <= entered_month)
        {
         if (current_month == entered_month)
           {
            var entered_day = entered_date.getDate();
            var current_day = today.getDate();
            if (current_day < entered_day)
               denied = true;
           }
         else denied = true;
        }
     }
   else
     denied = true;
  }
if (denied)
  {
   alert("Incorrect Birthday.");
   return false;
  }
}
document.getElementById("caspioform").onsubmit=check_date;
</SCRIPT>

I hope, it helps.

Link to comment
Share on other sites

  • 3 years later...
<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function (event) {
function check_date()
{
var field_name = "FIELDNAME";
var allowed_years = 15;

field_name = "InsertRecord" + field_name;
var entered_value = document.getElementById(field_name).value;
var entered_date = new Date(entered_value);
var entered_year = entered_date.getFullYear();
var today = new Date();
var current_year = today.getFullYear();
var denied = false;

if(current_year - entered_year <= allowed_years)
  {
   if (current_year - entered_year == allowed_years)
     {
      var entered_month = entered_date.getMonth();
      var current_month = today.getMonth();
      if (current_month <= entered_month)
        {
         if (current_month == entered_month)
           {
            var entered_day = entered_date.getDate();
            var current_day = today.getDate();
            if (current_day < entered_day)
               denied = true;
           }
         else denied = true;
        }
     }
   else
     denied = true;
  }
if (denied)
  {
   alert("Incorrect Birthday.");
   return false;
  }
}
document.getElementById("caspioform").onsubmit=check_date;
  
});
</script>

Hi @bookish,

I think the reason why this codes has stopped working for you is because of the release 13.0 of the platform on  July 11, 2018,  because of this release some of the JavaScript codes that we already have needs to be updated. For more details about this you can check this link https://howto.caspio.com/release-notes/caspio-bridge-13-0/13-0-impacted-areas/

You can also try to use the code above, and see if that works. I just added some line of code in it.

And you can also try to disable the Ajax loading in your DataPage by clicking the the check box http://prntscr.com/lx292i , you can see this option in the  'DataPage Data Source' tab  / part of your DataPage.


Regards,

TsiBiRu

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