Rihan
Rihan

Reputation: 31

Jquery intercept the cancel click, when I select a file

in my case, when I click on choose file input I i set a variable to 1.

Once you choose the file this variable remains at 1.

if it cancels, closes the window without selecting a file to upload I would like to return this variable to 0 it possible?

tnx

Upvotes: 0

Views: 3869

Answers (1)

halex
halex

Reputation: 16403

If I understand you correct I would go the other way. If you click the file chooser set the variable to 0, and only set the variable to 1 if the value of the file input changes.

Html

<input type="file" id="file"/>

Js

var x = 0;
$('#file').click(function() {
    x = 0;
});
$('#file').change(function() {
    x = 1;
});

See http://jsfiddle.net/JWRgY/ for a demo.

Upvotes: 1

Related Questions