Getting input field name when clicked

On my site I use 10 boxes to upload files. I want to get the name of the file upload field when I click on this field.

This means the first boot box, the second boot box, the third boot box, etc.

Therefore, if I click on the first boot box, I want to get the name of this window for downloading files.

How can I get the name of the download button in ajax function.

This is my ajax code:

$(function(){
    var countfile = 10;
    var strfileid = '';


    for(i=1;i<=countfile;i++){
    var btnUpload=$('#browse'+i);

    var adinfoid=$('#adinfoid').val();
    new AjaxUpload(btnUpload, {
        action: '<?php echo base_url()?>index.php/post/upload_editgalleryimage/'+adinfoid,
        name: 'uploadfile',
        onSubmit: function(file, ext){
        alert(btnUpload.Name);
            var photoplancnt=$('#photoplancnt').val();
            var hidcountimg=$('#hidcountimg').val();
            if(parseInt(hidcountimg)>=parseInt(photoplancnt)){
                $("#photoerror").html('maximum '+photoplancnt +' files are allowed');
                $("#photoerror").css('display','block');
                return false;
            }
            if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))){
                $("#photoerror").html('Only JPG, PNG, GIF, files are allowed');
                $("#photoerror").css('display','block');
                return false;
            }           
        },
        onComplete: function(file, response){ 

            if(response){                   
                    $(".upload_main_div").html('');
                    $(".upload_main_div").html(response);

                    var insid = $("#hiddengalidnow").val();
                    calltoloadimage(insid);
                    /*$("#galimageicon").attr("src",response);  
                    $("#galimageicon").attr("width",55);
                    $("#galimageicon").attr("height",55);*/
                    //$("#mainimageicon1").attr("src",response);

            }else{
            alert("error");
            }
        }
    }); 
    }
});

He will warn "browse12" at any time.

HTML code:

<?php
for($i=1;$i<=10;$i++){
?>
<input type="button" id="browse<?php echo $i;?>" name ="browse<?php echo $i;?>" class="browse_media" value="Browse">
<?php
}
?>
+3
source share
3 answers

Finally

alert(this._button.name);
+3
source

Generally:

$('input[type=file]').on('click', function() {
 var name = $(this).attr('name'); // or this.name
});

for you:

btnUpload.attr('name');
0
source

Maybe this will help

$("input[id^=browse]").click(function(){
var strBrowseName = $(this).attr('name'); 
// Or no var, if it has already been defined 
});
0
source

All Articles