check the script for it at w3schools.com, you will definitely get answer of your question there