Wednesday, July 4, 2012
Restrict file extension using JQuery
$(function() {
$("input[type=button]").click(function() {
if (!$("input[type=file]").val()) {
alert("Select file to Upload !");
return false;
}
var allowedTypes = ["jpg", "jpeg", "gif", "png"];
var path = $("input[type=file]").val();
var ext = path.substring(path.lastIndexOf('.') + 1).toLowerCase();
if (allowedTypes.lastIndexOf(ext) == -1) {
alert("Select valid file i.e.\n" + allowedTypes);
}
alert("Valid file selected");
});
});
Sunday, July 1, 2012
JQuery checkboxes implementation
I found many queries about "how we will make multiple check/unchecked button using JQuery, as well as how to count selected check boxes and then delete the selected records?". Its too easy!
Before working on this example I want to say, always follow the documentation of the product because you will found answers for many questions. Searching on internet not just take your a lot of time but you make yourself addicted of copy and paste.
$(function() {
$("input[rel=main]").click(function() {
$("input[rel=records]").attr("checked", this.checked);
var c = $("input[rel=records]:checked").length;
$("div > span").text((c > 1) ? c + " records are selected" : c + " record selected");
});
$("input[rel=records]").click(function() {
var c = $("input[rel=records]:checked").length;
$("div > span").text((c > 1) ? c + " records are selected" : c + " record selected");
if ($("input[rel=records]").length == $("input[rel=records]:checked").length) {
$("input[rel=main]").attr("checked", "checked");
} else {
$("input[rel=main]").removeAttr("checked");
}
});
$("input[type=button]").click(function() {
var n = $("input[rel=records]:checked").length;
if (n <= 0) {
alert("Select at least one record to delete");
} else if (n >= 1) {
var answer = confirm("Are you sure you want to delete " + n + " record(s)?");
if (answer) {
$("input[rel=records]:checked").parent().hide();
$("input[type=button]").after((n > 1) ? " " + n + " records are deleted :)" : " " + n + " record deleted :)");
$("input:checkbox").removeAttr("checked");
$("div > span").text("");
}
}
});
});
Subscribe to:
Posts (Atom)