In this article, we will create a progress bar using JavaScript. Here we show two examples of a Progress Bar Image. Now we discuss the first one, for this follow these steps:
Step 1: First we create a table and put four columns in it.
- <table style="width: 1257px" >
- <tr>
- <td ></td>
- <td >
- <table border="1">
- <tr>
- <td id="td1" class="style8"> </td>
- <td id="td2" class="style8"> </td>
- <td id="td3" class="style8"> </td>
- <td id="td4" class="style8"> </td>
- </tr>
- </table>
- </td>
- <td></td>
- <td></td>
- </tr>
-
- </table>
Step 2: After that, we write the Show() function on the onload event of the <body> tag. So when the page is loaded the function will be called.
- <body onload="Show()">
- .....
- ...
- </body>
Step 3: Now we write the JavaScript function. In this function, first, we change the color of the first column, then we call another function with the help of setTimeout and then we change the color of the second column, like this:
- <script language="javascript" type="text/javascript">
- function Show()
- {
- document.getElementById('td1').style.backgroundColor='Blue';
- document.getElementById('td2').style.backgroundColor='White';
- document.getElementById('td3').style.backgroundColor='White';
- document.getElementById('td4').style.backgroundColor='White';
- setTimeout("Show1()",300);
- }
- function Show1()
- {
- document.getElementById('td2').style.backgroundColor='Blue';
- document.getElementById('td1').style.backgroundColor='White';
- document.getElementById('td3').style.backgroundColor='White';
- document.getElementById('td4').style.backgroundColor='White';
- setTimeout("Show2()",300);
- }
- function Show2()
- {
- document.getElementById('td3').style.backgroundColor='Blue';
- document.getElementById('td1').style.backgroundColor='White';
- document.getElementById('td2').style.backgroundColor='White';
- document.getElementById('td4').style.backgroundColor='White';
- setTimeout("Show3()",300);
- }
- function Show3()
- {
- document.getElementById('td4').style.backgroundColor='Blue';
- document.getElementById('td2').style.backgroundColor='White';
- document.getElementById('td3').style.backgroundColor='White';
- document.getElementById('td1').style.backgroundColor='White';
- setTimeout("Show()",300);
- }
- </script>
The Output will be
Now we look at another example of a progress bar.
Step 1: First we create a table like this and put some columns in it.