Jump to content

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

 

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

Link to post
Share on other sites
  • 1 year later...

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