Jump to content

Script for an Submission Form Error based on multiple criteria.


Recommended Posts

I am creating a sales form which produces an error if there is not enough available quantity. I am using virtual fields and the below script is successful.  The script below produces the error when Virtual 8 is > either Virtual 7 OR Virtual 3.   I need to add to it to produce the error when Virtual 8 is greater than Virtual3 OR Virtual7 OR Virtual11 OR  Virtual14.

NOTE: Virtual3 will always have a value, while only one of Virtual 7, 11 or 14 will ever have a value.  

<script>
document.addEventListener('BeforeFormSubmit', function(ev) {


var virtual3 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual3]`).innerText;
var virtual7 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual7]`).innerText;
var virtual8 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual8]`).innerText;

 

if (virtual8 > virtual3 || virtual8 > virtual7 ) {
ev.preventDefault();
alert("Error: Not enough spaces! Please chose a tour with more availability");
}

})
</script>

Would anyone be able to help with this script? 

Link to comment
Share on other sites

Please try this code. If you have any problems please provide export of your app without sensative data in order to customize more deeply.

 

<script>
        document.addEventListener('BeforeFormSubmit', function(ev) {
    
        
        var virtual3 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual3]`).innerText;
        var virtual7 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual7]`).innerText;
        var virtual8 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual8]`).innerText;
        var virtual11 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual11]`).innerText;
        var virtual14 = +document.querySelector(`[action*="[@cbAppKey]"] [id*=cbParamVirtual14]`).innerText;
         
        
        if (virtual8 > virtual3 || virtual8 > virtual7 || virtual8 > virtual11 || virtual8> virtual14) {
        ev.preventDefault();
        alert("Error: Not enough spaces! Please chose a tour with more availability");
        }
        
        })
       
</script>

 

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