Forum Moderators: open
function checkNumOnly(thisField) {
if (/[^0-9¦,¦.]/.test(thisField.value)) {
thisField.style.backgroundColor='#ff6666';
alert("Du skrev:\n" + thisField.value + "\n\nmen kun tall er tillatt.");
thisField.focus();
}
} when i tab out of the input field (and i have letters or something there to trigger the alert) the cursor doesn't get put back in the input field, it goes to the next thing on the page:
Text2 <input type="text" name="txtfld2" value="" onblur="checkNumOnly(this);" />
You could try something like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
</style>
<script type="text/javascript">
</script>
</head>
<body>
<input type="text" onfocus="fldx=this" />
<input type="text" onfocus="fldx.focus();" />
</body>
</html>
A possible alternative... instead of checking the value on the blur event, you could check it on the form submit event, as part of some validation. Then highlighting and setting the focus should be easier (I think).
Good luck