javascript - How to get ID of input field from form using jQuery element selector -
i have form each input field unique id , have attached jquery on 'input' form. want id of field on user change value using jquery function. missing puzzle in following code in alert(".... statement
$(document).ready(function () { $("#createstudentprofileform").on('input', function () { alert($(this).find().closest().attr('id')); }); });
html form
<input class="form-control text-box single-line valid" data-val="true" data-val-number="the field student uwl id must number." data-val-range="only number allowed" data-val-range-max="2147483647" data-val-range-min="0" data-val-required="require student uwl id" id="studentnumber_uwlid" name="studentnumber_uwlid" value="" type="number">
i have many instances of input field above
how if attach event each field individually?
$(document).ready(function () { $("#createstudentprofileform").find("input,textarea,select").on('input', function () { alert(this.id); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="createstudentprofileform"> <input type="text" id="input1"> <input type="text" id="input2"> <input type="text" id="input3"> </form>
Comments
Post a Comment