473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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

<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
1 9875
Banfa
9,065 Expert Mod 8TB
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

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

Similar topics

5
by: 'bonehead | last post by:
Greetings, I'm still something of a newbie to html/php/mysql. I have a php/html form with several fields of type "input". If the user enters improper data in a particular field and clicks the...
2
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish...
6
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is...
5
by: tshad | last post by:
I have a date validation function that I want to stay at the object I am validating if there is a Validation error, but it always goes to the next object. The Javascript: function...
0
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after...
8
by: Cylix | last post by:
Any way to define the length of a textfield? I have just set all the field with a width so that they look like clear and easy to read, However, When I see the page of mac os, They are totally...
7
by: saurabh | last post by:
Hey, I have a form in which there are say 10 fields. I am using validator control for all the fields. suppose user forgets to fill field no. 5, 8 , 9 and 10. So on clicking the save...
3
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.