Jump to content

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;

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


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



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?

Link to comment
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

You can find more details in this article:


Hope this helps.




Link to comment
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') {
} else if (parseFloat(document.getElementById("cbParamVirtual13").value)=='Missing Data') {
              window.alert("You are missing data");    }



Link to comment
Share on other sites

  • 3 years later...

Hi rgiljohann.

Not sure if this still actual thread.

You can  use parseFloat to convert a number-like string  (e.g. "1.44" or "3123.3221" etc.) into a number. You are trying to convert 'Missing Data' into a number, which will return NaN, and then compare it with a string, so it will never return true, therefore  window.alert("You are missing data") statement will never be executed.
So you do not need to wrap document.getElementById("cbParamVirtual13").value into parseFloat before comparing it with 'Missing Data'

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.

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.

  • Create New...