473,385 Members | 1,642 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,385 software developers and data experts.

Check form

wj
Hi all,

Im trying to, deal with a problem that drives me crazy!

Im useing the following code to chech the fields of a form before
really submitting them:

-------
<script language="JAVASCRIPT">

function CheckForm()
{
var f = document.register;
var error_mes = '';
var submitOK="True";
if (f.place.value.length < 3)
{
error_mes = error_mes + "\n - No place.";
SubmitOK = "False";
}
if (f.provi.options[f.provi.value].value == 0)
{
error_mes = error_mes + "\n - No province.";
SubmitOK = "False";
}
if (f.educa.options[f.educa.value].value == 0)
{
error_mes = error_mes + "\n - No education.";
SubmitOK = "False";
}
if (f.prof.value.length == ' ')
{
error_mes = error_mes + "\n - No profession.";
SubmitOK = "False";
}
if (f.civil.options[f.civil.value].value == 0)
{
error_mes = error_mes + "\n - No civil.";
SubmitOK = "False";
}
if (f.pass.value.length == ' ')
{
error_mes = error_mes + "\n - No password.";
SubmitOK = "False";
}
if (f.pass.value != f.pass_ch.value)
{
error_mes = error_mes + "\n - No password check.";
SubmitOK = "False";
}
if (f.email_1.value.length < 4)
{
error_mes = error_mes + "\n - No e-mail.";
SubmitOK = "False";
}
if (f.email_1.value != f.email_2.value)
{
error_mes = error_mes + "\n - No e-mail check.";
SubmitOK = "False";
}
if (SubmitOK=="False")
{
alert(error_mes);
return false
}
}
</script>
---------

When i leave all the field empty and don't use the dropdown-boxes,
everything works fine; I get an error message and the form is not
submitted. But when i enter text or use the first three or four field
and leave the others blank, i don't get an errormessage and the data
is submitted.
Can anyone tell me how to deal with it??

Thanx!!
WJ
Jul 23 '05 #1
3 1755
Ivo
"wj" wrote
if (f.prof.value.length == ' ')
if (f.civil.options[f.civil.value].value == 0)
if (f.pass.value.length == ' ')


The length property always returns a number, sometimes 0, sometimes more. A
value is always a string, sometimes an empty string (of length 0), sometimes
a string which represents a number, such as "0" or "123". You probably want
to change the above lines to

if (f.prof.value.length == 0)
if (f.civil.options[f.civil.value].value == '')
if (f.pass.value.length == 0)

HTH
Ivo
Jul 23 '05 #2
wj wrote:
<script language="JAVASCRIPT">
<script type="text/javascript">
function CheckForm()
{
var f = document.register;
function CheckForm(f)
{
f = f.elements;
if (f)
{
var error_mes = '';
var submitOK="True";
var submitOK = true;
if (f.place.value.length < 3)
if (f['place'].value.length < 3)

{
error_mes = error_mes + "\n - No place.";
SubmitOK = "False";
error_mes += "\n - No place.";
SubmitOK = false;
}
if (f.provi.options[f.provi.value].value == 0)
if (f['provi'].options[f['provi'].selectedIndex].value == 0)
{
error_mes = error_mes + "\n - No province.";
SubmitOK = "False";
See above.
}
if (f.educa.options[f.educa.value].value == 0)
if (f['educa'].options[f['educa'].selectedIndex].value == 0)
[...] {
error_mes = error_mes + "\n - No education.";
SubmitOK = "False";
See above.
}
if (f.prof.value.length == ' ')
`length' is a number property and as such never equals ' '.
You probably meant

if (f['prof'].value.length == 0)

where f['prof'].value would be the *empty* string ('').
{
error_mes = error_mes + "\n - No profession.";
SubmitOK = "False";
See above.
}
if (f.civil.options[f.civil.value].value == 0)
See above.
{
error_mes = error_mes + "\n - No civil.";
SubmitOK = "False";
See above.
}
if (f.pass.value.length == ' ')
See above.
[...]
if (SubmitOK=="False")
if (! SubmitOK)
{
alert(error_mes); }
}
return SubmitOK;
}

</script>
---------
<form action="..." name="register" onsubmit="return CheckForm(this)">
...
</form>
When i leave all the field empty and don't use the dropdown-boxes,
everything works fine; I get an error message
What error message that was may have been important.
and the form is not submitted.
Of course.
[...]

PointedEars

P.S.
The word "I" is always capitalized in English.

P.P.S.
Your From: address is invalid:
| 550 5.1.1 <wz*@jongnederland.nl>... User unknown
Jul 23 '05 #3
Thomas 'Ingrid' Lahn wrote:
wj wrote:
var error_mes = '';
var submitOK="True";
^^^^^^^^
var submitOK = true; ^^^^^^^^
if (f.place.value.length < 3)

if (f['place'].value.length < 3)
{
error_mes = error_mes + "\n - No place.";
SubmitOK = "False";

^^^^^^^^
error_mes += "\n - No place.";
SubmitOK = false;

^^^^^^^^
Note that ECMAScript and its implementations are case-sensitive.
If should be *always* either `SubmitOK' or `submitOK'.
PointedEars
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Dave Smithz | last post by:
Hi there, A PHP application I built has a section which lists a number of members to a club whose names each appear with a check box beside them that can be ticked. These check boxes are part...
0
by: Dakanali | last post by:
I have a previous form which user search if there is a domain name. Give the domain name and in xml send the data from domainName=rewuest.form("domainname") to the specify url which is below and i...
2
by: Edward | last post by:
The following html / javascript code produces a simple form with check boxes. There is also a checkbox that 'checks all' form checkboxes hotmail style: <html> <head> <title></title> </head>...
5
by: Steve Wylie | last post by:
I am constructing an HTML questionnaire and one of the questions requires people to rate some choices from 1 to 5, where 1 is their favourite and 5 is their least favourite: Car Bus Taxi cab...
15
by: Rey | last post by:
Howdy all. Appreciate your help with several problems I'm having: I'm trying to determine if the Visit subform (subformVisits) has a new record or been changed, i.e. dirty. The form that...
5
by: rob willaar | last post by:
Hi, How can i check is a form is disposed in framework 1.1 In framework 2.0 i can check Form.IsDisposed to check if a user closed the form
1
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
14
by: Ørjan Langbakk | last post by:
I have a form where the user has the possibility to enclose his name. email, address and phonenumber. I want to be able to check if some of the fields are filled - at least one. This is so that...
3
by: jsurkin | last post by:
I have a form that lists a single work request, with an attached continuous subform that lists specific items that are part of the request. Each item in the subform has a check box to indicate when...
5
by: Andrew Meador | last post by:
I have a form (Change Card List by Status) with a check box (cboNOT) and a list box (lstStatus). There is an Open Report button that opens a report (Report - Change Card List) which uses a query...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.