View Single Post
  #19 (permalink)  
Old 10-19-2007, 05:14 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How can you remove space from a text field?

Hi all....


<SCRIPT LANGUAGE="JavaScript"><!--
function replace(string,text,by) {
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;

var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;

var newstr = string.substring(0,i) + by;

if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),te xt,by);

return newstr;
}
//--></SCRIPT>

<FORM>
<INPUT NAME="myField" TYPE="TEXT" VALUE="1 2 3 4 5 6 7 8 9 0">
<INPUT TYPE="BUTTON" VALUE="Remove Spaces" onClick="this.form.myField.value=replace(this.form .myField.value,' ','')">
</FORM>

Thanks....
Reply With Quote