|
↑
Forms >>>
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">
function
replaceChars(entry)
{
out
=
"a";
add
=
"z";
temp
=
""
+
entry;
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;
}
</script>
In this example, all "a" characters are
changed to "z" <BR>
<form
name="subform">
<input
type=text
name=text
size=40
value="abcdabcd"><br>
<input
type=button
name=action
value="Done!"
onClick="replaceChars(document.subform.text.value);">
</form>
|
→
|