0

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?

4 Answers 4

1

You can use .val()

$('.remove-order').click(function(){
   $('#order_line_items_attributes_0_quantity').val()
});
Sign up to request clarification or add additional context in comments.

Comments

1
 $('.remove-order').click(function(){
     var input_val = $('#order_line_items_attributes_0_quantit').val();
     console.log(input_val);
 });

Comments

1
$('.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.

Comments

0

Try closest():

$('.remove-order').on('click', function(e){
  alert($(this).closest('td').find('input[name^=order]').eq(0).val());
});

Here,

  • .closest('td'), the nearest parent td.
  • .find('input[name^=order]'), all input with name attribute starting with order
  • .eq(0), first item in the list

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.