Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 90559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:53:32+00:00 2026-05-10T22:53:32+00:00

My users are presented a basically a stripped down version of a spreadsheet. There

  • 0

My users are presented a basically a stripped down version of a spreadsheet. There are textboxes in each row in the grid. When they change a value in a textbox, I’m performing validation on their input, updating the collection that’s driving the grid, and redrawing the subtotals on the page. This is all handled by the OnChange event of each textbox.

When they click the Save button, I’m using the button’s OnClick event to perform some final validation on the amounts, and then send their entire input to a web service, saving it.

At least, that’s what happens if they tab through the form to the Submit button.

The problem is, if they enter a value, then immediately click the save button, SaveForm() starts executing before UserInputChanged() completes — a race condition. My code does not use setTimeout, but I’m using it to simulate the sluggish UserInputChanged validation code:

 <script>   var amount = null;   var currentControl = null;    function UserInputChanged(control) {       currentControl = control;       // use setTimeout to simulate slow validation code       setTimeout(ValidateAmount, 100);   }    function SaveForm() {       // call web service to save value       document.getElementById("SavedAmount").innerHTML = amount;   }    function ValidateAmount() {       // various validationey functions here       amount = currentControl.value; // save value to collection       document.getElementById("Subtotal").innerHTML = amount;   } </script>  Amount:   <input type="text" onchange="UserInputChanged(this)"> Subtotal: <span id="Subtotal"></span> <button onclick="SaveForm()">Save</button> Saved amount: <span id="SavedAmount"></span> 

I don’t think I can speed up the validation code — it’s pretty lightweight, but apparently, slow enough that code tries to call the web service before the validation is complete.

On my machine, ~95ms is the magic number between whether the validation code executes before the save code begins. This may be higher or lower depending on the users’ computer speed.

Does anyone have any ideas how to handle this condition? A coworker suggested using a semaphore while the validation code is running and a busy loop in the save code to wait until the semaphore unlocks – but I’d like to avoid using any sort of busy loop in my code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:53:32+00:00Added an answer on May 10, 2026 at 10:53 pm

    Use the semaphore (let’s call it StillNeedsValidating). if the SaveForm function sees the StillNeedsValidating semaphore is up, have it activate a second semaphore of its own (which I’ll call FormNeedsSaving here) and return. When the validation function finishes, if the FormNeedsSaving semaphore is up, it calls the SaveForm function on its own.

    In jankcode;

    function UserInputChanged(control) {     StillNeedsValidating = true;     // do validation     StillNeedsValidating = false;     if (FormNeedsSaving) saveForm();  }  function SaveForm() {     if (StillNeedsValidating) { FormNeedsSaving=true; return; }     // call web service to save value     FormNeedsSaving = false; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 112k
  • Answers 112k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer RewriteRule does only check the URL path. But the query… May 11, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer You cannot. You can do it by using GET. With… May 11, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer This code will always give your current controller <%=( Url.RequestContext.RouteData.GetRequiredString("Controller"))… May 11, 2026 at 9:59 pm

Related Questions

I'm currently trying to build an application that inherently needs good time synchronization across
We have a hosted application that manages pages of content. Each page can have
I call my JavaScript function. Why do I sometimes get the error 'myFunction is
I'm currently writing a custom server control in ASP.net. My idea is to create

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.