Categories
Uncategorized

How to restrict my input type=“file” to accept only (png/jpeg) image files

I wanted to restrict my input file tag to accept only .png images. I had read about this **accept attribute **provided under the input tag. Firstly this feature is not supported by all the browsers out there (not even Firefox to some extent here is fiddle link to it). So here is what I had to […]

Categories
Uncategorized

How to open new window (popup) and center on screen

window.open : Creates a new secondary browser window and loads the referenced resource. <script type=”text/javascript”> function PopUpManager(url, title,w,h) { var left = (screen.width/2)-(w/2); var top = (screen.height/2)-(h/2); var targetWin = window.open (url, title, ‘width=’+w+’, height=’+h+’, top=’+top+’, left=’+left); } </script> Here is an example, click on this link to activate the popup. This has been tested with […]

Categories
Uncategorized

How to use for loop in javascript

You can use the For Loop in javascript just like you use it in any other language. Below is a for loop with an alert. The code is pretty self explanatory, in case of any doubts or suggestion please use the comment section below and I shall get back to you. [sourcecode language=”javascript”] <script type=”text/javascript”>function […]

Categories
Uncategorized

Show confirm using javascript

The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button. If the user clicks OK, the confirm method returns true. If the user clicks Cancel, the method returns false. Confirmation are most often used to confirm an important actions that are taking place on a website. […]

Categories
Uncategorized

Compare two Dates using Javascript

Before we begin this tutorial you might like to check on this. In the below example I have two date objects. I am using the .getTime() method of the date object to compare these dates and show an alert accordingly. var firstDate = new Date(“2/12/2012”); var secondDate = new Date(“2/12/2012”); // We can use all comparison […]

Categories
Uncategorized

Convert string to date in Javascript

Convert string to date using Javascript : At some point of time every one needs to convert a date which is in a text format (say read from a textbox) to a Javascript Date object. This articles precisely discusses this. {code type=javascript} // convert text to date.var date = new Date(“2/12/2012”); // Or lets say I […]

Categories
Uncategorized

How to override all styles in CSS

I recently came across a very unique requirement, I wanted to change all font-family(s) I had used for this site. I had defined font-family at many different places in divs, spans, h1s, h2s and where not, so I wanted some shortcut way to do this. Here is what I had used, {code type=CSS} * { […]

Categories
Uncategorized

Give a common CSS to all input tags

You may want to give all input tags a common CSS. That is you want all your Text Fields, Password Fields, Radio button, Submit buttons etc… all to have a common CSS. This can be done easily by simply including the below code in your CSS file as shown below. Here I am giving all […]

Categories
Uncategorized

Show text on image hover

Show text on image hover : It is a common requirement to show a text on hover of an image. I recently wanted to do the same. Below is the straight forward and simple solution for the same. Using the title tag, we can easily do so, check the code below {code type=html} <img src=”http://yassershaikh.com/wp-content/uploads/2012/03/sp-studio-1.jpg” alt=”My […]

Categories
Uncategorized

How to resize a window on page load

To resize a window we can use the window.resize() method. This method takes in two parameter one for height of the window and other for the width of the window. Now as I want the window to be resized on page load, I had used a small piece of Jquery for this. In the code […]