Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Submit button not consistently firing

I have an asp.net core razor form with a submit button. When the user clicks 'Update', the form calls a JavaScript function to prompt the user if they are sure they want to complete the request. This functionality has been working, but starting last week, the form will occasionally not save despite the user confirming that they want to complete the request.

<div class="form-group">
    <label asp-for="Requests.Complete" class="lblReq"></label>
    <select id="isComplete" asp-for="Requests.Complete" class="inputReq switch-disable">
        <option value="N">N</option>
        <option value="Y">Y</option>
    </select>
        <span asp-validation-for="Requests.Complete" class="text-danger"></span>
</div> 

   
<div class="form-group">
    <input type="submit" value="Update" class="btn btn-primary" onclick="return CompleteOrNot()" />
</div>


@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

<script type="text/javascript">
    $(document).ready(function () {
        
    function CompleteOrNot() {
        var value = ($("#isComplete").val());            
        if (value == "Y")
        {
            var retVal = confirm("Are you sure you want to complete this request?");
            window.history.go(-1);                
            if (retVal == true) {                    
                return true;
            }                
        }                   
    }
}

The user always gets prompted if they want to complete the request and sometimes the post goes through and other times it acts as though the user said no to the prompt (even though they did not). Do you have any suggestions on how to troubleshoot/correct this issue?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to submit the form when retVal is true,try to use the following code

<form method="post" id="myForm">
    <div class="form-group">
    <label asp-for="Requests.Complete" class="lblReq"></label>
    <select id="isComplete" asp-for="Requests.Complete" class="inputReq switch-disable">
        <option value="N">N</option>
        <option value="Y">Y</option>
    </select>
        <span asp-validation-for="Requests.Complete" class="text-danger"></span>
</div> 


    <div class="form-group">
        <input type="button" value="Update" class="btn btn-primary" onclick="CompleteOrNot()" />
    </div>
</form>
@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

    <script type="text/javascript">
        function CompleteOrNot() {
            var value = ($("#isComplete").val());
            if (value == "Y") {
                var retVal = confirm("Are you sure you want to complete this request?");
                if (retVal == true) {
                    $("#myForm").submit();
                }
            }
        }
        $(document).ready(function () {

            
        })

    </script>
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!