View Full Version : Looking for help with Javascript (please)

Mark A
12-18-2004, 06:42 AM
I've been looking at free scripts but don't seem to be able to find what I need. Would anyone be willing to help via email or instant messenger? I'm in the U.S., eastern time zone.

Problems I'm running into (besides the code itself) -
1. can't find a solution specific to my needs
2. available coding is too complex for what I need
3. I'm only a beginner and don't have a good grasp at what I'm trying to accomplish although I've written some code (for this particular problem) but it doesn't work

If anyone could help I would appreciate it. The main issues are -
1. password validation where the login and passwords are stored in an array
2. validating email addresses to verify that they contain an "@" and a "."
3. validating a birthdate entry just to see if it's a real date, I'm only looking to see if the month entered is between 1 and 12, the day is between 1 and 31, and the year is equal to or less than the current year

I can provide more detail on how it is to be set up if needed. Again, I'm not looking for advanced security measures or super-fancy scripts. Only rudimentary scripting that I can understand on my own (so I can learn from it). The majority of what I've seen is way out of my realm of understanding.

I sincerely appreciate any help.


12-18-2004, 07:46 AM
Are you looking for someone to make this for you? I'm sure you could get it done for the right price if you post in the work offers forum. If not, you should post your code you are having problems with. And passwords and loggins? Are you using server side for this?

Philip M
12-18-2004, 01:03 PM
There are lots of free scripts out there which should get you started.

Have a look for example at



Thank you for saying that you would appreciate any help rather than
discourteously thanking your benefactors in advance.

As has been pointed out, you can only have secure login with password using server side languages such as PERL, PHP etc. JavaScript coding can easily be read by any passer-by and provides no protection at all.

Mark A
12-19-2004, 02:56 AM
OK, I'll go ahead and embarass myself. Here's what I've got so far. You'll see what I mean by "not complicated". Right now when I run this, no matter what is typed in you still get the alert. It never gets a match with the user name and password in the array. I'm not looking for anything fancier than this. The only testing will be with either leaving the entries blank or by typing the exact data as seen in the array.

I've got two forms on the page. The first form accpts the userid and password. Then you press the login button. I need to bang the info typed in against the array info. If it doesn't have the exact name and password it sends the alert. I don't even need to check for blank entries or numeric characters. Yes, this is a horrible example of coding, but this will never be used in a real world situation. If the userid and password match one of the two in the array, the the cursor needs to land in the first field of the second form, on the same page.

var notvalid = "Please enter a valid login.";
var users = new Array(2);
users[0] = new Array("man1", "up", "nice", "Good_guy@msn.com", "06/15/1902");
users[1] = new Array("man2", "down", "naughty", "nasty@aol.com", "02/15/1906")

function first_validate(frm) {
if (frm.userid.value != users[0][0]
|| frm.userid.value != users[1][0]) {
return false;
} else {
if ((frm.userid.value == users[0][0]
&& frm.password.value == users[0][1])
|| (frm.userid.value == users[1][0]
&& frm.password.value == users[1][1]))
return true;

Willy Duitt
12-19-2004, 03:33 AM
Your problem is here:

if (frm.userid.value != users[0][0]
|| frm.userid.value != users[1][0]) {

In simple english it says if the input value does not match username one OR username two return false...

Since you can only input one username, the condition will be met because there will always be one that does not match...

What you want is: if the input value does not match username one AND username two return false...

Change the OR operator ( || ) to an AND operator ( && ) here:

if (frm.userid.value != users[0][0]
&& frm.userid.value != users[1][0]) {


BTW: I often find that it helps to debug logic errors by reading the code in simple english as above...

Mark A
12-19-2004, 04:43 AM
Thank you for the guidance!