Set value of input text field inside jquery.on -
i using jquery.on on input buttons identify button pressed. want set value of text field value 1 of attributes on input button pressed.
the jquery
$('input.btne').on('click', function () { var btn = $(":input[type=button]:focus"); var amount = btn.attr("amount"); $("#fee_amount").val(amount); });
the html
<input type="text" id="fee_amount" /> <input type="button" id="idf" class="btne" optiontext="my option text" amount="123.00" value="edit" />
i tried doing said undefined alert($("#fee_amount").val());
the amount correct , present not go fee_amount field. can shed light on doing wrong please?
you gave wrong id in selector txt_feeamount
should fee_amount
input have has id fee_amount
not txt_feeamount
note can source of event using $(this)
or this
instead of var btn = $(":input[type=button]:focus");
here :focus not make sense well.
$('input.btne').on('click', function () { $("#fee_amount").val($(this).attr('amount')); });
defining attribute have amount not practice. should use data-* attributes. amount attribute data-amount.
using data- define data attributes
html
<input type="text" id="fee_amount" /> <input type="button" id="idf" class="btne" optiontext="my option text" data-amount="123.00" value="edit" />
javascript
$('input.btne').on('click', function () { $("#fee_amount").val($(this).data('amount')); });
Comments
Post a Comment