Reputation: 12054
I have the next three input's :
<input type="file" name="first"/>
<input type="file" name="second"/>
<input type="file" name="third"/>
And I want to do something if the file is chosen. I have next function :
$(function() {
$('input[name="INPUT-NAME"]').change(function (){
alert("Selected");
});
});
Is there any way to pass a name
of the clicked input field to this function?
Upvotes: 2
Views: 51
Reputation: 115212
Use $(this).attr('name')
method or just this.name
for getting the name
attribute
$(function() {
$('input').change(function() {
alert("Selected" + this.name);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="file" name="first" />
<input type="file" name="second" />
<input type="file" name="third" />
Upvotes: 1