简体   繁体   中英

Getting values of two editorFor values and adding them up to see if it meets condition

I have a td in my row that includes an editorFor that looks like this

<td>
  @Html.EditorFor(x => x.Parts[i].Qty)
</td>

I have JQuery code that clones the row when a checkbox is clicked, my question is.. How can I add the value of the original EditorFor textbox to the value of the cloned editorFor textbox. In order to provide validation checks before the user submits the page.

Can this be done?

Here is my JQuery code that copies the row


        $(document).ready(function () {
            $('.tr_clonePart input.part-class').change(function () {

                let Id = $(this).attr('id');
                let partId = $(this).attr('data-partId');
                //getting closest tr
                var selector = $(this).closest('.tr_clonePart');
                if ($(this).prop("checked") == true){
                    // remove cloned row
                    $('#' + Id + 'clone').remove();

                    selector.find(".AllTxt").show();
                    selector.find(".editQty").hide();
                }
                else {
                    var $tr = $(this).closest('.tr_clonePart');
                    var $clone = $tr.clone();
                    $clone.find('td');
                    $tr.after($clone);
                    $($clone).find(".part-class").hide();
                    //var qtyInItem = $('input[name=Parts['+partId+"].QtyInItem").val()


                    $clone.find('input[type="radio"]').attr("name", (i, n) => n + 'clone');
                    $clone.attr('id', (Id) + "clone");
                    var clonedID = Id + "clone";
                    $($clone).append($("<td class= 'addRow' ><a href=\"javascript:add('" + clonedID + "')\">add row</a></td>"));
            

                }

            });

I dont see where you append your cloned checkbox but when cloning and appending the value of the checkbox comes along like in this example:

 var clonenbr = 0; $(".add-checkbox").on("click", (e) => { e.preventDefault(); var clone = $($("td")[0]).clone() clone.find('input[type="radio"]').attr("name", (i, n) => n + 'clone' + clonenbr++); $("tr").append(clone) });
 <html> <head> <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script> </head> <body> <table> <tr> <td> <input type="radio" name="aa" value="a" /> aa </td> </tr> </table> <br> <a href="#" class="add-checkbox">Add checkbox</a> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM