473,549 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form validation question

I have a form on a webpage and want to use JavaScript validation for the
form fields.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
I'm a total JavaScript newbie and am completely lost.

Thanks for reading!
Oct 22 '05 #1
16 2207
Hosh wrote on 22 okt 2005 in comp.lang.javas cript:
I have a form on a webpage and want to use JavaScript validation for
the form fields.
I have searched the web for form validation scripts and have come up
with scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they
be joined in some way together to be one script?
..............
function validate(x){
// this depends on your requirements
firstInput = x.blah.value
............... .
}
</script>

............
<form onsubmit='retur n validate(this)' >
<input name='blah' ..........
I'm a total JavaScript newbie and am completely lost.


Learn or hire someone. Validating is not a beginners job.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #2
Thanks for that.
Learn or hire someone. Validating is not a beginners job. That's the plan (learn). That's why I'm here.
"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ************@19 4.109.133.242.. . Hosh wrote on 22 okt 2005 in comp.lang.javas cript:
I have a form on a webpage and want to use JavaScript validation for
the form fields.
I have searched the web for form validation scripts and have come up
with scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they
be joined in some way together to be one script?


.............
function validate(x){
// this depends on your requirements
firstInput = x.blah.value
............... .
}
</script>

...........
<form onsubmit='retur n validate(this)' >
<input name='blah' ..........
I'm a total JavaScript newbie and am completely lost.


Learn or hire someone. Validating is not a beginners job.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #3
Hosh wrote on 23 okt 2005 in comp.lang.javas cript:
"Evertjan." <ex************ **@interxnl.net > wrote in message
Hosh wrote on 22 okt 2005 in comp.lang.javas cript:
I have a form on a webpage and want to use JavaScript validation for
the form fields.
I have searched the web for form validation scripts and have come up
with scripts that only validate individual fields, such as an "Email
Validation Script" or a "Phone Validation Script".
Is it ok to put all these scripts on page as they are or should they
be joined in some way together to be one script?
.............
function validate(x){
// this depends on your requirements
firstInput = x.blah.value
............... .
}
</script>

...........
<form onsubmit='retur n validate(this)' >
<input name='blah' ..........
I'm a total JavaScript newbie and am completely lost.


Learn or hire someone. Validating is not a beginners job.


[first thing to learn: do not toppost on usenet, please]
Thanks for that.
Learn or hire someone. Validating is not a beginners job.

That's the plan (learn). That's why I'm here.


Then, we are not going to do your job in programming, doing sonone elses
programming is a professional job, but if you supply a bit of code you
are troubled with, you usually will get all the help you could wish.

As I showed you above, set your goals in validation and try to make some
code, test it in the framework I showed bove, or a better plan, I you
have one, and test it.

Then return with your problems.

Did you read this NG's FAQ and archive yet?

primary faq:
<http://jibbering.com/faq/>

secondary faq:
<http://www.merlyn.demo n.co.uk/js-index.htm>

archive:
<http://groups.google.c om/group/comp.lang.javas cript>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #4
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.
Oct 23 '05 #5
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.


Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation
script for you, without you even trying, then yes you can to the wrong
newsgroup.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 23 '05 #6
"Hosh" <1@2.com> writes:
I have a form on a webpage and want to use JavaScript validation for the
form fields.
Ok. First describe, in words, which values are acceptable for which
fields, and what should happen if the values fail to validate.
I have searched the web for form validation scripts and have come up with
scripts that only validate individual fields, such as an "Email Validation
Script" or a "Phone Validation Script".
It's dangerous to use other people's validation scripts without
understanding them, because they might not do exactly what you want.
E-mail validation is a case where many scripts you find are too
restrictive, and not accepting a user's e-mail is a pretty sure way
to lose a customer (if one's site has such). Likewise phone number
validation should probably be prepared for foreign numbers as well.
Is it ok to put all these scripts on page as they are or should they be
joined in some way together to be one script?
Most likely the latter. Each validation script consistes of some
scaffolding that calls the script at certain times, some actual
tests on values, and a response if validation fails. You only
want the scaffolding and response once, but you want a test
for each value that you have requirements for.
I'm a total JavaScript newbie and am completely lost.


Ok, here is a template for making a validation script:

---
<script type="text/javascript">
/* a validation function called when the user tries to submit the form */
function validate(form) {
var success = true;
// for each value to validate:
var field1Value = form.elements['field1'].value;
if (! ... some test on the value ...) {
success = false;
// possibly note which field fails for the user.
}
// end for each
if (!success) {
// tell the user somehow, e.g., alert("Invalid values entered")
// but preferably a more descriptive text.
}
return success;
}
</script>
.....
<form action=".." onsubmit="retur n validate(this); ">
... <input type="text" name="field1" ... > ...
</form>

---

Such a validation script checks only when the user tries to submit.
It's also possible to validate a field as soon as the user leaves it
(or even when he presses a key, but that's usually considered too
intrusive), but what code you need depends on the description you
started out with of what it should do.
Also, never forget that client-side validation is only a convenience
to prevent a server round-trip that would fail anyway. The server must
always validate its input, whether the client does so or not.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 23 '05 #7

"Randy Webb" <Hi************ @aol.com> wrote in message
news:_-*************** *****@comcast.c om...
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.


Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation script
for you, without you even trying, then yes you can to the wrong newsgroup.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

You know, in my original post, my only question was:
"Is it ok to put all these scripts on one page as they are or should they be
joined in some way together to be one script?"

I don't really see any request whatsoever for someone to write a damned
script for me!
You should wander into some friendly newsgroups and see how they treat
people that are just trying to get their feet wet.
Sorry for the intrusion!
Oct 23 '05 #8
Hosh said the following on 10/22/2005 9:23 PM:
"Randy Webb" <Hi************ @aol.com> wrote in message
news:_-*************** *****@comcast.c om...
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.
Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation script
for you, without you even trying, then yes you can to the wrong newsgroup.


You know, in my original post, my only question was:
"Is it ok to put all these scripts on one page as they are or should they be
joined in some way together to be one script?"


Yes, you should combine them. But to be able to combine them you have to
have an understanding of what you are combining.
I don't really see any request whatsoever for someone to write a damned
script for me!
Fair enough.
You should wander into some friendly newsgroups and see how they treat
people that are just trying to get their feet wet.


You mean we aren't friendly? Awww shucks.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 23 '05 #9
Lee
Hosh said:


"Randy Webb" <Hi************ @aol.com> wrote in message
news:_-*************** *****@comcast.c om...
Hosh said the following on 10/22/2005 8:13 PM:
Obviously, I wandered into the wrong newsgroup.
I was only looking for some advice.


Please quote what you are replying to.

And that is what you got. Some advice. And it happened to be good advice
at that. If you came wanting someone to write a complete validation script
for you, without you even trying, then yes you can to the wrong newsgroup.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

You know, in my original post, my only question was:
"Is it ok to put all these scripts on one page as they are or should they be
joined in some way together to be one script?"

I don't really see any request whatsoever for someone to write a damned
script for me!


Imagine somebody dropping by a forum of electrical contractors and
saying that they found some wires in their wall, and they wonder if
they should just connect them together.

You might get the impression that they're an unfriendly lot.
In the first place, we can't tell you if code that we've never seen
can be easily combined into a single validation function.

Then there's the whole problem of the trouble that you can get into
working with code that you don't understand.

Whether or not it's really dangerous depends on what sort of data
you're collecting, how you're transmitting it, and what you're doing
with it on the back-end.

Oct 23 '05 #10

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

Similar topics

11
8731
by: Jim | last post by:
Hi, I keep getting form results emailed to me that would indicate a form from my web site is getting submitted with all fields blank or empty, but my code should preventing users from proceeding if they left any field blank. My guess is that someone is trying to hack the site using the form to gain entry or run commands -- I don't really...
6
4326
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web developers, but is relevant discussion. i'm not OT here unless someone thinks i'm trolling (which i'm not, obviously). then i'll disappear and...
6
1927
by: Drew | last post by:
I've already created a simple method of ensuring that all form feilds are filled out before the form is submitted to an ASP page for records to be added to the data base. (Sorry about the formating, my newsreader may make it a mess!) <script language="javascript"> <!-- function Check(form) {
2
2360
by: Tim Mills | last post by:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a message to tell the user if all the fields have been fill-out. If the user has missed some information the form re-displays with red "alerts" indicating...
1
1620
by: Colin Basterfield | last post by:
Hi, I have a web form which takes daily sales totals, both counts and monetary value and is done on a weekly basis, so on a Monday morning the User would enter these totals. Each total has a range, which at the lower end is >= 0 and the upper limit is configurable, these totals are then submitted to a web service which posts them to a data...
9
4158
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation...
27
4691
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it...
11
2970
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the...
18
5781
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client script code being executed having a flaw: function anonymous() { if (!ValidatedTextBoxOnKeyPress(event)) { event.cancelBubble = true; if...
0
7526
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7723
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7965
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6051
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5375
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.