copenndthagen
copenndthagen

Reputation: 50790

Customize input type=file behavior

I have a file browser on my page using

<input type="file" />

Now on click of the browse button, I need to show a JS "confirm" popup. Only on click of "OK" on that popup, I should show the file browser, else it should just cancel (not display the file browser/selector window)

Is it possible to achieve this?

Upvotes: 4

Views: 314

Answers (2)

Anujith
Anujith

Reputation: 9370

Just try this:

<input type="file" onclick="return confirm('Continue ?');"/>

DEMO

Or make use of onclick event handler:

 $('input[type=file]').click(function(){
    return confirm("Continue ?");
 });

DEMO2

Upvotes: 2

gdoron
gdoron

Reputation: 150313

$('input[type="file"]').click(function(){
    return confirm("Are you sure you want to see me dance?");
});

Live DEMO

Upvotes: 4

Related Questions