Disable button with jquery

I searched this site, I can not find the answer to my problem.

I have an HTML form that can upload multiple images. looks like that

    <form enctype="multipart/form-data" method="post">
  <p>
   <label for="image1">File number 1 to upload:</label>
   <input id="image1" type="file" name="file[]" >
  </p>
        <p>
   <label for="image1">File number 1 to upload:</label>
   <input id="image1" type="file" name="file[]" >
  </p>
    //etc etc
    </form>

What I want to do is disable each "select file" button after the image has been selected.

If this is not possible, can the success message be displayed in any way after each selection? (there can be up to 20 downloadable buttons.)

thank

+3
source share
5 answers

You have duplicate identifiers "image1". Perhaps this is only in your question, but if it is in your code, keep in mind that this is incorrect.

Here is a little faster:

$('input:file').change(function() {
    this.disabled = !!this.value;
});
+2
source

Try the following:

$(function(){
  $('#formID :file').change(function(){
    // if there is some value specified
     if (this.value){
       $(this).attr('disabled', 'disabled');
     }
  });
});

, . , , .

+1

change:

$('input[type="file"]').change(function() {
    if($(this).val().length)
       $(this).attr('disabled','disabled'); 

});
+1

I think this is the right listener for all types of image input.

$(document).ready(function() {
  //for all image inputs
  $("input:file").change(function(){
    //check if an image is submitted
    if(this.value){
        //disable element
        $(this).attr("disabled", true); 
    }
  });

});
+1
source

Thank you all for your help, but no one is working! Every time I used a script to disable a button, it canceled the download.

I really needed only a visual hint that the button was pressed, so I came up with this and it works on my PHP page.

$(".classclick$count").click(function(){

    $(".classclick$count").append("<span style=color:red;> < DONE </span>");

});
0
source

Source: https://habr.com/ru/post/1776092/


All Articles