Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda