Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i update data-reason attribute with selected value from drop down in my input element?

<table class='reorderTablerow'>
<tbody>
<tr>
<td>
<input data-item='item A' data-itemid='001' data-reason='' class='quanityborderinput' type=text/>
</td>
<td>
<select>
<option>Select reason</option>
<option>Out of stock</option>
<option>Damaged item</option>
</select>
</td>
</tr>
<tr>
<td>
<input data-item='item B' data-itemid='002' data-reason='' class='quanityborderinput' type=text/>
</td>
<td>
<select>
<option>Select reason</option>
<option>Out of stock</option>
<option>Damaged item</option>
</select>
</td>
</tr>
</tbody>
</table>


What I have tried:

so far my code jquery code is

Part of jQuery 
    var orderformcontainer = $(this).parent().parent();
    var timestamp = moment();
    var OrderFormType = $(this).attr("data-orderformtype");
    var quanityinputboxes=orderformcontainer.parent().find("tbody .quanityborderinput");

    var items = quanityinputboxes.filter(function (index) {
        return $(this).val().length > 0;
    });

    var orderitems = [];
    items.each(function (index, element) {
        var itemid = $(element).attr("data-itemid");
        var quantity = $(element).val();
        var name = $(element).attr("data-itemname");
		});
Posted
Updated 23-Jan-18 5:15am
v2
Comments
Karthik_Mahalingam 23-Jan-18 11:04am    
The Html table and Javascript code has no relation.
where is the button ?
what does "this" denotes?

do you want to update the textbox attribute on the same row when select box is changed?
istudent 23-Jan-18 11:06am    
There is a button on top. Right now I just need to pass the value selected from each selected list to its input element data-reason attribute.
istudent 23-Jan-18 11:23am    
Thank you sir.
Karthik_Mahalingam 23-Jan-18 11:25am    
welcome
istudent 25-Jan-18 14:36pm    
Sir I ran into an issue here.

1 solution

try

$(function () {

        $('.reorderTablerow tr select').change(function (a, b) {
            var value = a.target.value;
            var row = a.target.parentElement.parentElement; 
            $('.quanityborderinput', row).attr('data-reason', value); 
        });

    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900