Pad Form Text Box

[Total: 0    Average: 0/5]

This will pad the input into a form text box.

Body Code:

<script> 
/*
 * 2 parameters:
 *  - Form Item to pad.
 *  - Character to pad with.
 */
function padThis(_obj,_pad) {
  if(!_obj.size)return; /* this must be specified! */
  /* make it long enough */
  while(_obj.value.length<_obj.size)
  {
    _obj.value=""+_pad+_obj.value;
  }
  /* remove 1st character if it is the pad character and its too long */
  while(_obj.value.length>=_obj.size && _obj.value.split("")[0]==_pad)
  {
    _obj.value=_obj.value.substr(1,_obj.value.length);
  }
} 
</script> 
<form name="form1" method="post" action=""> 
  <p> 
    <input type="text" name="C4" size=5 onblur="padThis(this,'0')"> 
  </p> 
  <p> 
    <input type="text" size=12 name="textfield" onblur="padThis(this,' ')"> 
  </p> 
</form> 

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *