Jump to content

javascript to recalculate field values OR custom button to refresh fields prior to submission

Recommended Posts

Is it possible to count records in a table using javascript instead of a calculated field so the comparison is done right before submission? Or, is there a way to force fields with calculated values to refresh prior to submission? Possibly a custom button that refreshes the fields then submits the form?

I've run into a snag using calculated values. Virtual15  is a calculated value and counts how many of a courseID are scheduled for the selected Lesson Date

SELECT Count(Lessons_courseID)
FROM _v_active_lessons
WHERE Lessons_courseID=target.[@field:Lessons_courseID] AND Lesson_Date=target.[@field:Lesson_Date]

Virtual8 is also a calculated value that uses CASE WHEN to determine if it's ok to schedule. We can only teach one of each courseID per day. The case statement is checking for other restrictions as well, but they are not dependent on a record count from the active_lessons table.


WHEN [@cbParamVirtual15] <> 0
THEN 'This lesson is scheduled for another teacher today. Please select a different day.' 

ELSE 'ok to schedule'


Then, I use this  javascript in the footer to prevent form submission

<script type="text/javascript">

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

// prevent form submit if not ok to schedule
// if user forget to choose required fields date or time, proceed with submission to generate required field error
// alertok variable prevents blank alert box 

   var Input1 = document.querySelector("span[id^='cbParamVirtual8']").innerText;
   var alertok = 1;

if (Input1 == 'ok to schedule' || Input1 == ' ')

     if (alertok) {
         alertok = 0;

The issue: If the lesson is not already scheduled for a selected date,  two users can simultaneously select the same lesson for the same date and both will get the 'ok to schedule'. This allows both users to submit the form and I end up with double signups.


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