Script Categories

Forms >>> Replace Characters.

Replaces a character or multiple characters in a textbox when the visitor goes to the next field (or in this example, clicks the submit button).

In this example, all "a" characters are changed to "z"

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function replaceChars(entry) {
out = "a"; // replace this
add = "z"; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
document.subform.text.value = temp;
//  End -->
In this example, all "a" characters are changed to "z" <BR>
<form name="subform">

type=text name=text size=40 value="abcdabcd"><br>
<input type=button name=action value="Done!" onClick="replaceChars(document.subform.text.value);">

<!-- Or to make it change when the user clicks the next -->
<!-- field, use this instead of the previous two lines: -->

<!--  <input type=text name=text size=40 value="abcdabcd" onBlur="replaceChars(this.value);">  -->


JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).