Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Tuesday, January 25, 2011

jQuery/Javascript to replace broken images

Many times you find your image links are broken. In firefox, Chrome if your images links are broken then your images are hidden by default. If you see same scenario in IE it will show you 'X' image missing.

I found following snippet quite useful which hides broken images using jquery.



$(document).ready(function(){ 
    $("img").each(function(index) {
        $(this).error(function() {
            $(this).unbind("error").attr("src", "/images/NoImage.png"); // If you want to replace with any blank image.

            $(this).hide();//You can simply Hide it using this.
        });
        $(this).attr("src", $(this).attr("src"));
  });    
});

Hope you find it useful.

Monday, November 29, 2010

Validate input values using javascript

Many times you are using javascript for allowing user to input only numeric values or special character etc.

I would like to share few javascript functions that you would find quite handy.


#1 Allows disabling keypress




#2 Allows you to enter numbers only



#3 Allows you to enter numbers with comma



#4 Allows you to enter numbers with comma



#5 Allows you to validate no of characters for textbox.




I will keep adding new functions.

Thanks,
Ashish Chotalia