Jump to content
Sign in to follow this  
rgiljohann

Javascript to prevent update based on field values

Recommended Posts

I have used the forum to get to this point so you may have seen some of my code that I grabbed from other posts.

I have a single record update form, where I only want them to be able to select the update button if all of the fields are marked as 'complete'. It should be known that all of the 'complete' or 'missing data' fields are formulas in the table, however, I am referencing virtual fields in my code that are set to the formula fields. The url to my form is here: https://c5amf675.caspio.com/dp/32576000f879393a309d4a97b1bd

My code for checking the virtual field values is here:

<script language="JavaScript">
function check_numbers()
{
var disabled = false;
if (parseFloat(document.getElementById("cbParamVirtual").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtua2").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual3").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual4").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual5").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual6").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual7").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual8").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual9").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual10").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual11").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual12").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual13").value)=='Complete') disabled = true;
if (parseFloat(document.getElementById("cbParamVirtual14").value)=='Complete') disabled = true;

if (disabled)
{
alert("All fields must be complete");
return false;
}
}
document.getElementById("caspioform").onsubmit=check_numbers;
</script>

What is really weird, is that even the following code will not show a message when I click on the update button.

<SCRIPT LANGUAGE="JavaScript">

 function check()
 {
     window.alert("Thank you.. Information is registered!");
}

 document.getElementById("caspioform").onsubmit=check;

</SCRIPT>

I tried this small alert function after I couldn't get my regular code to work. This was on its own and did not work. I am thinking that there is an issue somewhere where the onclick is not registering. Do any of you have any idea what might be the problem?

Share this post


Link to post
Share on other sites

Hi @rgiljohann

Please note that Caspio form does not support on load event handlers and you need to use Caspio built-in event handlers.

The onload event should be replaced with Caspio built-in event as shown below:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
// do something
       
});
</script>

You can find more details in this article:

https://howto.caspio.com/deployment/

Hope this helps.

 

Regards,

Vitalikssssss

Share this post


Link to post
Share on other sites

Hello, thanks for the response. I tried the function below. cbParamVirtual13 right now is set to Missing Data, but it still allowed me to click update and everything worked.

 

<script type="text/javascript">
function f_submit() {
if (parseFloat(document.getElementById("cbParamVirtual13").value)=='Complete') {
document.getElementById("caspioform").update();
} else if (parseFloat(document.getElementById("cbParamVirtual13").value)=='Missing Data') {
              window.alert("You are missing data");    }

document.addEventListener('DataPageReady',f_submit);
</script>

 

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...