Reputation: 771
HTML
<td data-title="Quantity">
<div class="clearfix quantity r_corners d_inline_middle f_size_medium color_dark m_bottom_10">
<button class="btn-minus bg_tr d_block f_left" data-item-price="8000.0" data-direction="down">-</button>
<input min="0" class="f_left" type="text" value="2" name="order[line_items_attributes][0][quantity]" id="order_line_items_attributes_0_quantity">
<button class="btn-plus bg_tr d_block f_left" data-item-price="8000.0" data-direction="up">+</button>
</div>
<div>
<a href="#" class="color_dark remove-order"><i class="fa fa-times f_size_medium m_right_5"></i>Remove</a><br>
</div>
</td>
Javascript
$('.remove-order').click(function(){
????
});
How to get the value of the input text when remove is click?
Upvotes: 0
Views: 288
Reputation:
Try closest():
$('.remove-order').on('click', function(e){
alert($(this).closest('td').find('input[name^=order]').eq(0).val());
});
Here,
td
.order
Upvotes: 0
Reputation: 34227
$('.remove-order').click(function () {d
var myval="";
myval = $('input.f_left').val();
// or use:
myval = $('input.f_left')[0].value;
});
In this case those would both return the 2 value as a string. IF you want a number be sure to parse it with parseInt(myval);
NOTE: since you have an ID you should use that selector:
var myvalInt = parseInt($('#order_line_items_attributes_0_quantity').val(), 10);
as that would be the fastest method.
Upvotes: 1
Reputation: 13699
$('.remove-order').click(function(){
var input_val = $('#order_line_items_attributes_0_quantit').val();
console.log(input_val);
});
Upvotes: 1
Reputation: 2567
You can use .val()
$('.remove-order').click(function(){
$('#order_line_items_attributes_0_quantity').val()
});
Upvotes: 1