This piece of javascript is intented to remove any extraneous characters on the fly.
When I type enough characters to go beyond the textfield’s viewable area, the view jumps from the end (where I’m typing) to the beginning.
It looks like this happens whenever element’s value is set equal to something.
Is there a way to prevent the view from jumping around?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title></title>
<script type="text/javascript">
function valid_chars(elementId){
var regex = new RegExp("[^a-zA-Z0-9_-]", "gi");
var raw = elementId.value;
str = raw.replace(regex, "");
elementId.value=str;
}
</script>
</head>
<body>
<form>
<fieldset>
<input type="text" value="" size="20" onkeyup="valid_chars(this);" onchange="valid_chars(this);" onfocus="valid_chars(this);" />
</fieldset>
</form>
</body>
</html>