abacus
08-22-2004, 06:28 PM
Hi all,
When I validate in the <form return onSubmit="submitTest();"... focus() works fine.
Same with the <body onload="loader()"...
Same with the onClick="javascript: document.foo.text1.select(); document.foo.text1.focus()">. All the above works as expected.
But when I try to validate upon leaving a textbox, using onBlur, the alert works (when value.length == 0), but the focus still jumps on to the next object.
Using Netscape 7.x, how do I get the focus to remain on the textbox if the entry was bogus???
Code:
<script type="text/javascript">
// --------< loader fn
function loader() {
window.status="I'm in the function Loader";
document.getElementById('text1').value = "Start";
document.getElementById('text1').select();
document.getElementById('text1').focus();
}// ---------------------------------------------------
function validText1(element) {
if (element.value.length == 0) {
alert("You need to type something into TextBox One");
document.getElementById("text1").focus();
return false;
}
}
function validText2(element) {
if (element.value.length == 0) {
alert("You need to type something into TextBox Two");
document.getElementById("text2").focus();
return false;
}
}
function submitTest() {
if (document.foo.text1.value == "test") {
alert("Type something besides the word test in TextBox1");
document.foo.text1.focus();
document.foo.text1.select();
}
return false //always 'false' because there's no followup form
}
}
// -->
</script>
</head>
<body onload="loader()" bgcolor="#FFFFFF" text="#000000">
<p> </p>
<form name="foo" return onSubmit="submitTest();"><div align="center">
Enter up to eight characters in TextBox One
<input type="text" id="text1" name="text1" maxlength="8" size="10"
onBlur="return validText1(this)">
<br />
Enter up to eight characters in TextBox Two
<input type="text" id="text2" name="text2" maxlength="8" size="10"
onBlur="return validText2(this)">
<p> </p>
<input type="button" name=button1" value="Focus on TextBox One"
onClick="javascript: document.foo.text1.select(); document.foo.text1.focus()">
<input type="submit" id="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
When I validate in the <form return onSubmit="submitTest();"... focus() works fine.
Same with the <body onload="loader()"...
Same with the onClick="javascript: document.foo.text1.select(); document.foo.text1.focus()">. All the above works as expected.
But when I try to validate upon leaving a textbox, using onBlur, the alert works (when value.length == 0), but the focus still jumps on to the next object.
Using Netscape 7.x, how do I get the focus to remain on the textbox if the entry was bogus???
Code:
<script type="text/javascript">
// --------< loader fn
function loader() {
window.status="I'm in the function Loader";
document.getElementById('text1').value = "Start";
document.getElementById('text1').select();
document.getElementById('text1').focus();
}// ---------------------------------------------------
function validText1(element) {
if (element.value.length == 0) {
alert("You need to type something into TextBox One");
document.getElementById("text1").focus();
return false;
}
}
function validText2(element) {
if (element.value.length == 0) {
alert("You need to type something into TextBox Two");
document.getElementById("text2").focus();
return false;
}
}
function submitTest() {
if (document.foo.text1.value == "test") {
alert("Type something besides the word test in TextBox1");
document.foo.text1.focus();
document.foo.text1.select();
}
return false //always 'false' because there's no followup form
}
}
// -->
</script>
</head>
<body onload="loader()" bgcolor="#FFFFFF" text="#000000">
<p> </p>
<form name="foo" return onSubmit="submitTest();"><div align="center">
Enter up to eight characters in TextBox One
<input type="text" id="text1" name="text1" maxlength="8" size="10"
onBlur="return validText1(this)">
<br />
Enter up to eight characters in TextBox Two
<input type="text" id="text2" name="text2" maxlength="8" size="10"
onBlur="return validText2(this)">
<p> </p>
<input type="button" name=button1" value="Focus on TextBox One"
onClick="javascript: document.foo.text1.select(); document.foo.text1.focus()">
<input type="submit" id="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>