I have a click handler on a button that uploads a file. It checks the contents of each of the cells of the first column of a table against a predefined value and only proceeds on user confirmation. I can get the below to work but it doesn’t feel elegant. Any suggestions?
$('#upload').click(function() {
var proceed;
$('#mytable tr td:first-child').each(function(a, b) {
if ($(b).html() == 'x') {
proceed = confirm('u sure?');
return false;
}
});
return proceed;
});
EDIT:
I want to do something like the following i just dont know the correct syntax (and this doesnt work):
$('#upload').click(function() {
return $('#mytable tr td:first-child').each(function(a, b) {
if ($(b).html() == 'x') {
return confirm('u sure?');
}
});
});
Here is one way to simplify your code at the very least
Here is a jsfiddle showing the modified code in action: http://jsfiddle.net/Akkuma/R5Mzt/ (updated to be more accurate)
I just ran a quick test in IE7, IE9, and Chrome and found the input’s file value to be unique enough that it could not run into a contains problem. Both output C:\fakepath\nameoffile.png.