提交按钮不始终发射

发布于 2025-02-05 03:15:45 字数 1395 浏览 1 评论 0原文

我有一个带有提交按钮的ASP.NET Core Razor表单。当用户单击“更新”时,表单调用JavaScript函数以提示用户确定要完成请求。该功能一直在起作用,但是从上周开始,尽管用户确认他们想完成请求,偶尔也不会保存该表格。

<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;
            }                
        }                   
    }
}

如果用户想完成请求,则总是会出现提示,有时帖子会通过,而其他时间,它的作用似乎是用户对提示说不的(即使他们没有)。您对如何进行故障排除/纠正此问题有任何建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2025-02-12 03:15:45

如果您想在retval为true时提交表格,请尝试使用以下代码

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

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>
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文