OT: Winning entry in Javascript Monday Blah . . .
Bradley Miller
bradmiller at dslonramp.com
Tue Sep 3 22:13:39 CDT 2002
To call this I do this:
<input type="text" name="Price" value="" maxlength="10" size="10"
onBlur="javascript:stripBadchs('Price','dollar value');">
I'm going to have to experiment a bit with a solution that Ray Holmes
mailed me privately . . . this seems to work on Netscape, but I haven't
tried it everywhere else yet. (*sigh* -- freakin' 10,000 versions of
browswers . . . )
<script>
<!--
// Expects to receive the name or the identifier for a form object (id)
// and a string (status) indicating what characters are permissible.
function stripBadchs(idin,status) {
id = eval("document.MDA_EDIT."+idin+".value");
var bad = 0
for (i = 0; i < id.length; i++) {
ch = id.substring(i, i + 1);
if ( status == "letters or numbers" ) { if ( (ch < "a" || "z" < ch) &&
(ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) ) { bad = 1; } }
if ( status == "letters" ) { if ( (ch < "a" || "z" < ch) && (ch < "A"
|| "Z" < ch) ) { bad = 1; } }
if ( status == "dollar value" ) { if ((ch == "$") || (ch == ",")) {
bad = 1 } }
if ( status == "numbers" ) { if (ch < "0" || "9" < ch) { bad = 1 } }
if ( bad == 1 ) {
id = id.substring(0,i)+id.substring(i+1,id.length)
i=i-1
bad = 0
}
}
document.MDA_EDIT.eval(idin).value = id;
}
// -->
</SCRIPT>
More information about the Kclug
mailing list