How do I prevent a form file input element from changing via the onclick DOM event when using the confirm() method?
In example I want to give a user the opportunity to not lose the value of a file input element by asking them if they wish to Ok|cancel, if they click cancel the file dialog window should not be displayed.
XHTML
<input name="post_file" onclick="images_change();" type="file" value="" />
JavaScript
function images_change()
{
var answer = confirm('Okay or cancel, if you cancel no dialog window will be displayed.');
if (answer)
{
answer = true;
//previous item previews deleted here in a while loop.
}
else {answer = false;}
return answer;
}
Why not just inline it if you have the one file input?
HTML:
<input name="post_file" onclick="return check()" type="file" value="" />
JavaScript:
function check() {
return confirm('Okay or cancel, if you cancel no dialog window will be displayed.');
}
jsFiddle example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With