开发者

Check if textbox has changed. If so, update field.

开发者 https://www.devze.com 2023-04-11 04:43 出处:网络
I have a textbox named \"discount\". And a table called \"PriceTable\" which has dynamically added rows (). Inside each row is a td with the classname/ID \"discountField\". When Discount changes, each

I have a textbox named "discount". And a table called "PriceTable" which has dynamically added rows (). Inside each row is a td with the classname/ID "discountField". When Discount changes, each discount field must change to reflect this. I can do the logic fine, but how do I cycle through each box and append values?

so far I have:

 $(function () {
        var content = $('#discount').val();

        $('#discount').keyup(function () {
            if ($('#emp_discount').val() != content) {
                content = $('#emp_discount').val();
                //Change detected at discount - Add validation too


                $('#discountField').each(function () {
                    //dostuff alert("test");
                });


                //end discount

       开发者_运维技巧     }
        });
    });

This lets me find out when the field is changed. but not sure about changing the values.

This is a snippet of the table.

<tr class="row" onmouseover="this.className='row_selected">
                        <td>1
                        </td>
                        <td>
                            £0
                        </td>
                        <td>
                            £100000
                        </td>
                        <td>0.0035 %
                        </td>
                        <td id="discountField">
                            1
                        </td>
                    </tr>

`


Couple of things

(1) Do you have multiple rows with the discountField column? If so then you should consider setting the class instead of id to discountField

<td class="discountField">
                        1
</td>

(2) To set the value of the column you would do

$('.discountField').each(function () {
                $(this).html(content)
});


When cycling just use this

$("#discountField").html("new value");

If you want it recalculated you just insert the calculated new value.

0

精彩评论

暂无评论...
验证码 换一张
取 消