[wpseo_breadcrumb]

how to disable button on change using jquery

Solutons:


you can do this as am assuming a image and am checking the resolutions and then i disable or enable the button as per requirements and also am clearing selected
image so user can’t upload the wrong format .

<script>




    var _URL = window.URL || window.webkitURL;

                                    $("#file").change(function (e) {
                                        var file, img;


                                        if ((file = this.files[0])) {
                                            img = new Image();
                                            img.onload = function () {
                                                //alert(this.width + " " + this.height);
                                                var widthofimage = this.width;
                                                var heightofimage = this.height;

                                                if (widthofimage < 1920 && heightofimage < 850 || widthofimage != 1920 && heightofimage != 850 || widthofimage > 1920 && heightofimage > 850) {
                                                    swal({
                                                        title: "Please review",
                                                        text: "Please Upload Image of 1920 X 850",
                                                        icon: "error",
                                                    });

                                                    document.getElementById("file").value = "";
                                                } else {

                                                    $('input[type="submit"]').removeAttr('disabled');

                                                }

                                            };
                                            img.onerror = function () {
                                                alert("not a valid file: " + file.type);
                                            };
                                            img.src = _URL.createObjectURL(file);


                                        }

                                    });






</script>

You can disable html input elements by the following ways:

1 :- $(this).attr(“disabled”, true);

2 :- $(this).prop(‘disabled’, true);

Try The following code:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#fileUpload").change(function(){
        //$(this).attr("disabled", true);
        $('#btnTest').prop('disabled', true);
        });
});
</script>
</head>
<body>
<input ID="fileUpload"  runat="server" type="file">
<button type="button" id="btnTest">CLICK ME</button>

</body>
</html>

    $(document).ready(function(){
        $("#fileUpload").change(function(){
            //$(this).attr("disabled", true);
            $('#btnTest').prop('disabled', true);
            });
    });
  
<!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  
    </head>
    <body>
    <input ID="fileUpload"  runat="server" type="file">
    <button type="button" id="btnTest">CLICK ME</button>
    
    </body>
    </html>

Related Solutions

What is a “toast notification”?

A Toast is a non modal, unobtrusive window element used to display brief, auto-expiring windows of information to a user. Android OS makes relatively heavy use of them. Here's an example of a Google Chrome toast notification on Mac OS X: A list of descriptions...

Which elliptic curve should I use?

You are misreading Bernstein and Lange's advice (admittedly, their presentation is a bit misleading, with the scary red "False" tags). What they mean is not that some curves are inherently unsafe, but that safe implementation of some curves is easier than for...

How can I find files that are bigger/smaller than x bytes?

Use: find . -type f -size +4096c to find files bigger than 4096 bytes. And : find . -type f -size -4096c to find files smaller than 4096 bytes. Notice the + and - difference after the size switch. The -size switch explained: -size n[cwbkMG] File uses n units of...

Relative imports in Python 3

Explanation From PEP 328 Relative imports use a module's __name__ attribute to determine that module's position in the package hierarchy. If the module's name does not contain any package information (e.g. it is set to '__main__') then relative imports are...

How to add a class to a given element?

If you're only targeting modern browsers: Use element.classList.add to add a class: element.classList.add("my-class"); And element.classList.remove to remove a class: element.classList.remove("my-class"); If you need to support Internet Explorer 9 or lower: Add...

less searches are always case-insensitive

I'm not sure how to enable this from the command line but when you're inside of less you can toggle the behavior you want by giving the -i command to less. toggling -i                searching for /blah and /BLAH               searching for /Blah       ...

Is using nested try-catch blocks an anti-pattern?

This is sometimes unavoidable, especially if your recovery code might throw an exception. Not pretty, but sometimes there are no alternatives. I don't think its an antipattern, just widely misused. Most nested try catch's are indeed avoidable and ugly as hell,...

How to pass a range into a custom function in Google Spreadsheets?

So I've searched long and hard for a good answer to this and here is what I have found: an unmodified range parameter passes in the values of cells in the range, not the range itself (as Gergely explained) ex: when you do this =myFunction(a1:a2) to use a range...

Create a branch in Git from another branch

If you like the method in the link you've posted, have a look at Git Flow. It's a set of scripts he created for that workflow. But to answer your question: git checkout -b myFeature dev Creates the MyFeature branch off dev. Do your work and then git commit -am...

How can I set customise settings for htop?

htop has a setup screen, accessed via F2, that allows you to customize the top part of the display, including adding or removing a "Load average" field and setting it's style (text, bar, etc.). These seem to be auto saved in $HOME/.config/htop/htoprc, which...

Is there any way to manually bring up the keyboard?

As I see an alternative keyboard may solve your issue, and this seems to be an acceptable solution, and you even mention something you cannot find -- hereby I proudly present: Hacker's Keyboard Checking its Guide, there's in fact a section suggesting such a...

How to get rid of “No match found” when running “rm *”

This behaviour is controlled by several of Zsh's globbing options. By default, if a command line contains a globbing expression which doesn't match anything, Zsh will print the error message you're seeing, and not run the command at all. You can disable this in...

So what are logical cpu cores (as opposed to physical cpu cores)?

Physical cores are just that, physical cores within the CPU. Logical cores are the abilities of a single core to do 2 or more things simultaneously. This grew out of the early Pentium 4 CPUs ability to do what was termed Hyper Threading (HTT). It was a bit of a...

How to append date to backup filename

This isn't working because the command date returns a string with spaces in it. $ date Wed Oct 16 19:20:51 EDT 2013 If you truly want filenames like that you'll need to wrap that string in quotes. $ touch "foo.backup.$(date)" $ ll foo* -rw-rw-r-- 1 saml saml 0...

What does __all__ mean in Python?

Linked to, but not explicitly mentioned here, is exactly when __all__ is used. It is a list of strings defining what symbols in a module will be exported when from <module> import * is used on the module. For example, the following code in a foo.py...

Is the linux kernel ported to JavaScript yet?

Javascript is not a systems programming language, it is not appropriate for a kernel. Additionally, the kernel is a very large body of code, and "porting" it to another language is not something that can be done easily, and would likely take years. If the...