从数据库中的文本框中加载数据,然后更新数据jquery更改事件不起作用

时间:2018-10-03 15:32:39

标签: javascript jquery model-view-controller

我正在执行更新操作,请在弹出窗口中按“编辑”按钮加载数据,当我更新任何字段然后更改事件不被调用时。更改事件用于在文本中显示说明。 在PurchaseCodeU网格中调用此函数以填充此文本框值 txtUPurCode ,然后在我更改某些内容但未更改事件时调用。 谁能告诉我我哪里错了,我的代码有什么问题。

jquery

<script>
    // Purchase Code For Update


        var purchaseCU = $("#txtUPurCode").val();
        PurchaseCodeU(purchaseCU);

        function PurchaseCodeU(purchaseCU) {

            $.ajax({
                url: "/Home/chartofAccount",
                type: "GET",
                contentType: "application/json;charset=UTF-8",
                data: {
                    'glCode': purchaseCU

                },
                dataType: "json",
                success: function (result) {
                    $('#UPurCodeDescription').val(result);
                },
                error: function (errormessage) {
                    alert(errormessage.responseText);
                }
            });
            return false;
        }

        $('#txtUPurCode').change(function () {

            var pC = $("#txtUPurCode").val();

            function PUC(pC) {

                $.ajax({
                    url: "/Home/chartofAccount",
                    type: "GET",
                    contentType: "application/json;charset=UTF-8",
                    data: {
                        'glCode': pC

                    },
                    dataType: "json",
                    success: function (result) {
                        $('#UPurCodeDescription').val(result);
                    },
                    error: function (errormessage) {
                        alert(errormessage.responseText);
                    }
                });
                return false;
            }
        })

</script>

HTML

         <!---  For Update Item Category --> 

            <form action="" method="post">
                <div class="modal fade left" id="ItemCUpdateModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
                     data-backdrop="false">
                    <div class="modal-dialog modal-side modal-top-left modal-notify modal-info" role="document">
                        <!--Content-->
                        <div class="modal-content" style="margin-left:68%;">
                            <!--Header-->
                            <div class="modal-header">
                                <p class="heading lead">Update Item Category</p>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true" class="white-text">&times;</span>
                                </button>
                            </div>
                            <!--Body-->

                            <div class="modal-body" style="width:80%">


                                <h3 id="Result"></h3>

                                <div class="form-row">
                                    <div class="col">
                                        <!-- Requisition Req_NO -->
                                        <div class="md-form">

                                            @Html.TextBoxFor(m=>m.CatCode, new { @class = "form-control mr-sm-3", @id = "txtUCatCode", Required = true })
                                            <label for="lblItemDesc">Category Description</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <!-- Requisition Date -->
                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.CatDesc, new { @class = "form-control mr-sm-3", @id = "txtUCategoryDesc", @placeholder = "Item Description", Required = true })

                                            <label for="lblItemDesc">Category Description</label>
                                        </div>
                                    </div>


                                </div>

                                <div class="form-row">
                                    <div class="col">
                                        <!-- Requisition Date -->
                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.HS_Code, new { @class = "form-control mr-sm-3", @id = "txtUHsCode", @placeholder = "HS Code" })

                                            <label for="lblHsCode">HS Code</label>
                                        </div>
                                    </div>

                                    <div class="col">
                                        <!-- Requisition Date -->
                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.PurCode, new { @class = "form-control mr-sm-3", @id = "txtUPurCode", @placeholder = "Pur Code", Required = true })

                                            <label for="lblRequisitionDatepicker">Pur Code</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <!-- Job -->
                                        <div class="md-form">

                                            <input type="text" id="UPurCodeDescription" class="form-control mr-sm-5" />
                                            <label for="lbljob">Description</label>
                                        </div>
                                    </div>

                                </div>

                                <div class="form-row">
                                    <div class="col">

                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.SaleCode, new { @class = "form-control mr-sm-3", @id = "txtUSaleCode", @placeholder = "Sale Code" })

                                            <label for="lblNsaleCode">Sale Code</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <!-- Job -->
                                        <div class="md-form">
                                            <input type="text" id="USaleCodeDescription" class="form-control mr-sm-5" />
                                            <label for="lblSaleCodeDesc">Description</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-row">
                                    <div class="col">
                                        <!-- Requisition Date -->
                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.CostOfSaleCode, new { @class = "form-control mr-sm-3", @id = "txtUCostOfSaleCode", @placeholder = "Cost Of Sale Code" })

                                            <label for="lblNCostOfSaleCode">Cost of Sale Code</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <!-- Job -->
                                        <div class="md-form">
                                            <input type="text" id="UCostOfSaleCodeDescription" class="form-control mr-sm-5" />
                                            <label for="lblNCostOfSaleCodeDescription">Description</label>
                                        </div>
                                    </div>
                                </div>

                                <h6 style="color:black; display:none">For Trade Only</h6>

                                <div class="form-row" style="display:none">
                                    <div class="col">

                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.SaleCode_Trade, new { @class = "form-control mr-sm-3", @id = "txtUSaleCode_Trade", @placeholder = "Sale Code Trade" })

                                            <label for="lblNSaleCode_Trade">Sale Code</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <!-- Job -->
                                        <div class="md-form">
                                            <input type="text" id="USaleCodeDescriptionTrad" class="form-control mr-sm-5" />
                                            <label for="lblNCostOfSaleCodeDescriptionTrade">Description</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-row" style="display:none">
                                    <div class="col">

                                        <div class="md-form">

                                            @Html.TextBoxFor(m => m.CostOfSaleCode_Trade, new { @class = "form-control mr-sm-3", @id = "txtUCostOfSaleCode_Trade", @placeholder = "Cost Of Sale Code Trade" })

                                            <label for="lblNCostOfSaleCodeTrade">Cost Of Sale Code Trade</label>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <!-- Job -->
                                        <div class="md-form">
                                            <input type="text" id="UCostSaleCodeDescT" class="form-control mr-sm-5" />
                                            <label for="lblNCostOfSaleCodeTradeDesc">Description</label>
                                        </div>
                                    </div>
                                </div>




                            </div>
                            <div class="justify-content-center">
                                <div class="modal-footer">
                                    <button type="reset" class="btn btn-default" data-dismiss="modal">Close</button>
                                    <button id="btnItemCUpdate" type="submit" class="btn btn-danger " onclick="ItemCategory_Update();">Update</button>
                                </div>
                            </div>
                            <!-- Default form contact -->

                        </div>
                        <!--Footer-->

                    </div>
                    <!--/.Content-->
                </div>
            </form>

1 个答案:

答案 0 :(得分:0)

请参阅W3C文档here,要使jquery .val()起作用,输入字段必须具有名称属性。

尝试一下:

   <input type="text" id="UPurCodeDescription" name= "UPurCodeDescription" class="form-control mr-sm-5" />

引用线程here