72dpi
01-11-2006, 01:14 AM
Ever wanted a progress bar on a contact form?
This nifty bit of css & javascript allows you to do just that.
havea play with the code, adjust the colors to suit, and then you can adapt it to subdreamers own contact form.:
I have made mine a maximun of 400 charactors.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple Text counter and Progress Bar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" type="text/JavaScript">
function textCounter(field,counter,maxlimit,linecounter) {
****// text width//
****var fieldWidth =**parseInt(field.style.width);
****var charcnt = field.value.length;********
****// trim the extra text
****if (charcnt > maxlimit) {
********field.value = field.value.substring(0, maxlimit);
****}
****else {
****// progress bar percentage
****var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit);
****document.getElementById(counter).style.width =**parseInt((fieldWidth*percentage)/100)+"px";
****// color correction on style from CCFFF -> CC0000
****setcolor(document.getElementById(counter),perc entage,"background-color");
****}
}
function setcolor(obj,percentage,prop){
****obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
</script>
<style type="text/css">
<!--
.progress {
****width: 1px;
****height: 2px;
****background-color:#92B700;
****border:1px solid #000;
}
-->
</style>
</head>
<body>
<form method="post" action="contact.php">
****<h1>Contact Form</h1>
<!-- Start Message Field-->
************Message (* Max 400 characters)
************<br />
**************<textarea style="width:300px" name="userMessage" cols="63" rows="8" wrap="VIRTUAL" class="inputbox" title="enter maximum 400 characters" onKeyDown="textCounter(this,'progressbar1',400)" onKeyUp="textCounter(this,'progressbar1',400)" onFocus="textCounter(this,'progressbar1',400)" ></textarea>
************ <br />
************<div id="progressbar1" class="progress"> </div>
************<script>textCounter(document.getElemen tById("maxcharfield"),"progressbar1",400)</script>
************<br />
********
********<!-- Start Submit Button-->
************<input type="submit" name="submit" value="Send" />
</form>
</body>
</html>
have fun & enjoy!
This nifty bit of css & javascript allows you to do just that.
havea play with the code, adjust the colors to suit, and then you can adapt it to subdreamers own contact form.:
I have made mine a maximun of 400 charactors.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple Text counter and Progress Bar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" type="text/JavaScript">
function textCounter(field,counter,maxlimit,linecounter) {
****// text width//
****var fieldWidth =**parseInt(field.style.width);
****var charcnt = field.value.length;********
****// trim the extra text
****if (charcnt > maxlimit) {
********field.value = field.value.substring(0, maxlimit);
****}
****else {
****// progress bar percentage
****var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit);
****document.getElementById(counter).style.width =**parseInt((fieldWidth*percentage)/100)+"px";
****// color correction on style from CCFFF -> CC0000
****setcolor(document.getElementById(counter),perc entage,"background-color");
****}
}
function setcolor(obj,percentage,prop){
****obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
</script>
<style type="text/css">
<!--
.progress {
****width: 1px;
****height: 2px;
****background-color:#92B700;
****border:1px solid #000;
}
-->
</style>
</head>
<body>
<form method="post" action="contact.php">
****<h1>Contact Form</h1>
<!-- Start Message Field-->
************Message (* Max 400 characters)
************<br />
**************<textarea style="width:300px" name="userMessage" cols="63" rows="8" wrap="VIRTUAL" class="inputbox" title="enter maximum 400 characters" onKeyDown="textCounter(this,'progressbar1',400)" onKeyUp="textCounter(this,'progressbar1',400)" onFocus="textCounter(this,'progressbar1',400)" ></textarea>
************ <br />
************<div id="progressbar1" class="progress"> </div>
************<script>textCounter(document.getElemen tById("maxcharfield"),"progressbar1",400)</script>
************<br />
********
********<!-- Start Submit Button-->
************<input type="submit" name="submit" value="Send" />
</form>
</body>
</html>
have fun & enjoy!