Click here to Skip to main content
Licence CPOL
First Posted 11 Oct 2006
Views 25,641
Bookmarked 22 times

Percentage Bar

By | 15 Feb 2012 | Article
Display a simple percentage bar easily using Javascript and CSS

Sample Image - Percentage_Bar.jpg

Introduction

In a recent project, a percentage bar was needed to show what percentage of the work had been completed. As a result, I came up with a simple way by using the <hr> and <span> HTML tags with simple CSS and Javascript to create the percentage bar.

The overall concept is easy: First use a <span> tag to wrap around the <hr>. Then, by setting the <span> tag border style, the border of the bar can be modified. Also, by changing the height of <hr>, the bar height can be adjusted.

Code

Here is the code actually used in this project:

<html>
<head>
<style>
span
{
border-bottom: thin solid gray;
height: 15pt;
width: 100pt;
}
hr
{
height: 10pt;
color: blue;
}
</style>
<script>
function change(x)
{
  document.all.process.width=x+'%';
}
</script>
</head>

<body>
<span ><hr width=80%  id = "process" name = "process"  align=left></span>
<br>
<input name=input type=text />
<a onclick="change(document.all.input.value)">% SET</a>
</body>

</html>

If anyone knows a different way to do this, please contact me or leave a message here. Thank you all.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

jebberwocky



China China

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDid well PinmemberVishram14:48 25 Oct '06  
GeneralRe: Did well Pinmemberjebberwocky0:27 20 Nov '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 15 Feb 2012
Article Copyright 2006 by jebberwocky
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid