Jump to content
Sign in to follow this  
Ras2019

Java Script Prevent Submission

Recommended Posts

Hi,

I've been fiddeling with preventing a submissionform to submit and I have seen a few solutions in the forum. However it seems i cant get those to work, perhaps because i try to rewrite them a bit to fit my purpose.

This is what I am trying to achieve:

  • I have two calculated virtual fields. These display the text WARNING if other fields exceed some values. (This works)
  • If the two Virtual Fields display the warnings I want the form to prevent submission and high-light with alert the existing warnings.

Below script prevent submission completely regardless if there are warnings in the virtual fields or not... and there are no alert either.:

 

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function(event) {
event.preventDefault();

var Input1 = document.getElementByName('cbParamVirtual1').value;
var Input2 = document.getElementByName('cbParamVirtual2').value;
     if (Input1 === 'WARNING' || Input2 === 'WARNING') {
alert('Enter acceptable volume!');

} else {

document.forms["caspioform"].submit();

}

});
</script>

 

I would appreciate if anyone could point me in the right direction, getting the script to work.

Thanks a lot in advance.

Sincerely

Ras

 

Share this post


Link to post
Share on other sites

Hi @Ras2019,

The way you trying to refer to Virtual fields is incorrect. 

I would recommend using query selectors with contains type of match.

This code should work fine:

<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var Input1 = document.querySelector("span[id^='cbParamVirtual1']").innerHTML;

var Input2 = document.querySelector("span[id^='cbParamVirtual2']").innerHTML;

     if (Input1 === 'WARNING' || Input2 === 'WARNING') {
event.preventDefault();

alert('Enter acceptable volume!');


} else {

document.forms["caspioform"].submit();

}

});
</script>

Regards,

vitalikssssss

Share this post


Link to post
Share on other sites

Hello,

 

You may also want to check on this thread


It shows how to prevent form submissions using Caspio Standard Features. With regards to showing an error message, you may show/hide and HTML Block using rules.

 

Hope this helps.

[src="carl.js"]

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