By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

how to set focus back to a textfield after validation in a jsp page if it is wrong

P: 2
<html>
<body>
<form method="POST" name="f1">

<input type="text" name="t1" onchange="validate(this.value)" >
<input type="text" name="t2" onchange="validate(this.value)">


</form>

<script language="javascript">

document.f1.t1.focus();
function validate(string) {

var valid="123456789"
for (var i=0; i< string.length; i++) {
if (valid.indexOf(string.charAt(i)) < 0) {
f1.t1.focus()
alert('not a number')

return false;
}
}

return true;
}
function validate1(string) {

var valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ RSTUVWXYZ"
for (var i=0; i< string.length; i++) {
if (valid.indexOf(string.charAt(i)) < 0) {
alert('invalid characters');
return false;
}
}

return true;
}
</script>

</body>
</html>
Jun 30 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,964
Just posting code without stating the problem your are experiencing or the question you wish to ask is unlikely to get (m)any responses. Tell us what the problem is.

Also if you use the [html] and [/html] your posted code will be all formated and colourful, like this

[html]
<body>
<form method="POST" name="f1">

<input type="text" name="t1" onchange="validate(this.value)" >
<input type="text" name="t2" onchange="validate(this.value)">


</form>

<script language="javascript">

document.f1.t1.focus();
function validate(string) {

var valid="123456789"
for (var i=0; i< string.length; i++) {
if (valid.indexOf(string.charAt(i)) < 0) {
f1.t1.focus()
alert('not a number')

return false;
}
}

return true;
}
function validate1(string) {

var valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ RSTUVWXYZ"
for (var i=0; i< string.length; i++) {
if (valid.indexOf(string.charAt(i)) < 0) {
alert('invalid characters');
return false;
}
}

return true;
}
</script>

</body>
</html>[/html]
Jun 30 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.