Validation

J

john

I need Help!!! Please I need to write a javascript that will do the
following

Show a user name
User address
User Phone Number
City
State
zip code
telephone number
and date of Birth

I already have that part of the code done then what I have to do is add
validation so if any of these are left blank they get a message
indicating which box is left blank and point it out then I have to add
cookies so if the user information is the same it will ask take them to
antoher page telling them that their information is already there..
Here is my code so far can some one please help me with the rest.. I
really have no idea how to do this part and it is due this thirsday.

Thank you..


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
</script>
<title>Web 420</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<table border="0" height="338" width="75%">
<tbody>
<tr>
<td width="56%">
<h4>Personal Information</h4>
<form name="input" action="thankyou.htm" method="get">
<pre> First Name: <input name="firstname" size="20"
type="text"><br><br><br> Last Name: <input name="lastname"
size="20"
type="text"><br><br><br> Address: <input name="address" size="20"
type="text"><br><br><br> City: <input name="city" size="20"
type="text"><br><br><br> State:
<select><option>Alabama</option><option>Alaska</option><option>Arizona</option><option>California</option><option>Colorado</option><option>Connecticut</option><option>Delaware</option><option>Florida</option><option>Georgia</option><option>Hawaii</option><option>Idaho</option><option>Illinois</option><option>Indiana</option><option>Iowa</option><option>Kansas</option><option>Kentucky</option><option>Lousisana</option><option>Maine</option><option>Maryland</option><option>Massachusetts</option><option>Michigan</option><option>Minnesota</option><option>Mississippi</option><option>Missouri</option><option>Montana</option><option>Nebraska</option><option>Nevada</option><option>New
Hampshire</option><option>New Jersey</option><option>New
Mexico</option><option>New York</option><option>North
Carolina</option><option>North
Dakota</option><option>Ohio</option><option>Oklahoma</option><option>Oregon</option><option>Pennsilvania</option><option>Rhode
Island</option><option>South Carolina</option><option>South
Dakota</option><option>Tennessee</option><option>Texas</option><option>Utah</option><option>Vermont</option><option>Virginia</option><option>Washington</option><option>West
Virginia</option><option>Wisconsin</option><option>Wyoming</option></select>
<br><br> Zip Code: <input name="zip" size="6"
type="text"><br><br><br> Telephone Number: <input
name="phone" size="11" type="text"><br><br><br> Date of Birth:
<input
name="phone" size="10" type="text"><br> <br><input value="Submit"
type="submit"><br><input name="Reset2" value="Reset"
type="reset"></pre>
&nbsp;</form>
</td>
</tr>
</tbody>
</table>
</body>
</html>
 
D

deneb

John,

About the client-side validations :

1.Give an ID to your input.
2.You can add a mecanism to trim spaces of the value entered by your
user
function stringTrim (s) {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
String.prototype.trim = stringTrim;

2. Now you can use that prototype to check your strings :
if(document.getElementById('txtAddress').value.trim()=="") {
alert('You must specify your address');
document.getElementById('txtAddress').focus();
return false;
}

About the cookies stuff :

Do you use any server-side technology like ASP / PHP or are you using
plain HTML combined with javascript? if it is the former than you don't
need cookies in order
to check if a user is already registered. Just make the checkup
server-side in your database / xml file. It will be more robust...
remember that people can remove
their cookies anyway.

But if you don't have any server-side technology, I think you can
access cookies this way in Javascript. I saw this on newsgroups and
never tested it so
forgive me if it is wrong =) :

To write :
var exp=new Date(2010,1,1); // cookie's expiration date
document.cookie = "CookieName=CookieValue; expires=exp.toGMTString()";


To read :
just parse what is into document.cookie the way you want.

Good luck
François
 
J

john

Thank you for you Help..
As far what you were talking about on the server side there is no
server. I understand what you say about the cookies but this is just
for a school project to get a grade it not going on an actual web site.
Any more help would be appreciated.. Also how do I take them to another
page to display that their information is already there??


Thank you..
John
 
D

deneb

Hello John,

To redirect the user to another page you can use
1) window.location='mynewpage.html';
or
2) window.navigate('mynewpage.html');

If you want a good javascript reference, you can go to that site :
http://www.devguru.com/. It may as well contains cookies
reading/writing examples.

Good luck
François
 
R

Randy Webb

deneb said the following on 7/19/2006 9:01 AM:
Hello John,

To redirect the user to another page you can use
1) window.location='mynewpage.html';
Yes.

or
2) window.navigate('mynewpage.html');
No.

If you want a good javascript reference, you can go to that site :
http://www.devguru.com/.

You said "good javascript reference", that is not a good one. It is not
even close. So, after you go there, go somewhere else looking for a
better one. Try the group FAQ.....
It may as well contains cookies reading/writing examples.

If its cookie code is as poor as the examples I looked at, stay away
from it.

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 
D

deneb

Randy said:
deneb said the following on 7/19/2006 9:01 AM:

No.

I didn't know that this function was depreciated, my bad.
You said "good javascript reference", that is not a good one. It is not
even close. So, after you go there, go somewhere else looking for a
better one. Try the group FAQ.....

Why are you saying this? Last time I checked it was fine. There may
exists better references but devguru isn't all that bad. The group FAQ
may be a better starting point though, I didn't think about it.

Regards,
François
 
R

Randy Webb

deneb said the following on 7/20/2006 10:12 AM:
Why are you saying this?

Hmmm. Because it's true?
Last time I checked it was fine.

When did you check it and what is your criteria for "fine"?

Let me give you a few examples of the "fine" quality it has, fair enough?

setAttribute is known to be buggy in IE. Yet, devguru has not one
mention in the entry for setAttribute that says it is buggy in IE. What
good is a reference if it gives the false impression that something is
reliable when it isn't?

Nest. eval.

This is what devguru says about eval:

<quote>
The top-level function, eval, evaluates and/or executes a string of
JavaScript code that is contained in the codestring argument.
</quote>

First, it doesn't "evaluate and/or executes", it executes what you give
it. Plain and simple.

But, that is *all* that it says about eval. And there is no way on the
planet you can even come close to explaining eval in that one sentence.
And even then, that one sentence is patently wrong.

Shall I continue?

The site might be a basic minimum site to get a little information from,
but it is nowhere near a "good reference".
There may exists better references but devguru isn't all that bad.

There are many better references and yes, devguru, is that bad.
The group FAQ may be a better starting point though, I didn't think about it.

The FAQ for this group is a better starting point than 99.99% of the JS
sites on the web.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Thu, 20 Jul 2006 14:23:34 remote, seen in
Randy Webb said:
This is what devguru says about eval:

<quote>
The top-level function, eval, evaluates and/or executes a string of
JavaScript code that is contained in the codestring argument.
</quote>

First, it doesn't "evaluate and/or executes", it executes what you give
it. Plain and simple.

There's no clear distinction between the terms in English as applied to
Javascript.

If the string supplied contains an expression, with no assignment, then
"evaluates" is a perfectly good description.

If the purpose of the eval(...) is to return a quantity, i.e. the usage
is as X = eval(S) , then "evaluates" is a perfectly good
description, even if S contains assignments.

The description "evaluates" is only inappropriate if the return value of
the eval(S) is (whether or not defined) irrelevant, the code being
executed for its side effects.


Consider an input control which is given a string S such as '3+5' from
which Number 8 is required. At the ECMA-spec level, "executes" might be
appropriate; but in normal English discourse, "evaluates" would be used.
- and ISTM that a corresponding statement might well apply in "deneb"'s
native language.
 
J

john

To whomever want's tp Help Me

The Program Below is what I am working with.. I need to do a cookie
redirect, so if the user has for example already enterd their name and
it is stored
in a cookie it goes to another page called Error.htm and give them a
message saying they already filled out the form.
Please I have looked this up on diffrent pages on the internet and
tried to consolidate their part with mine but I can not get it to work.

Can some one please just add to my program that is below how to do the
cookie redirect part and help me out.
please disregard the validation part I already got that piece to work..
Thank you.. I appreciate your help in advance..
I have worked on this all weekend cutting and pasting from the
internet and modifiying but I can't get it to work right.. It is not
like I am just asking for answers I have
given it 100% effort but honestly I am not good at programing and this
might be a simple task for you programers out there but it is a
nightmare for me.


Thank you
I need Help!!! Please I need to write a javascript that will do the
following

Show a user name
User address
User Phone Number
City
State
zip code
telephone number
and date of Birth

I already have that part of the code done then what I have to do is add
validation so if any of these are left blank they get a message
indicating which box is left blank and point it out then I have to add
cookies so if the user information is the same it will ask take them to
antoher page telling them that their information is already there..
Here is my code so far can some one please help me with the rest.. I
really have no idea how to do this part and it is due this thirsday.

Thank you..


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
</script>
<title>Web 420</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<table border="0" height="338" width="75%">
<tbody>
<tr>
<td width="56%">
<h4>Personal Information</h4>
<form name="input" action="thankyou.htm" method="get">
<pre> First Name: <input name="firstname" size="20"
type="text"><br><br><br> Last Name: <input name="lastname"
size="20"
type="text"><br><br><br> Address: <input name="address" size="20"
type="text"><br><br><br> City: <input name="city" size="20"
type="text"><br><br><br> State:
<select><option>Alabama</option><option>Alaska</option><option>Arizona</option><option>California</option><option>Colorado</option>
<option>Connecticut</option><option>Delaware</option><option>Florida</option><option>Georgia</option><option>Hawaii</option>
<option>Idaho</option><option>Illinois</option><option>Indiana</option><option>Iowa</option><option>Kansas</option><option>Kentucky
</option><option>Lousisana</option><option>Maine</option><option>Maryland</option><option>Massachusetts</option><option>Michigan</option>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top