Click to See Complete Forum and Search --> : Verify.


DanUK
03-16-2003, 09:18 PM
Hi again - hope you all had a great weekend.
This is a 'snippet' from some code I'm using to validate forms, the ones I want to ask about are the following:

else if (form.newPASS.value =="") {
alert("Please include your new password.");
form.newPASS.select(); }

else if (form.newPASS2.value =="") {
alert("Please repeat your new password.");
form.newPASS2.select(); }

It all works lovely, however how can I get it to show an alert if the two passwords entered do not match? any help you can give me will be much appreciated ! Thanks.

AdamBrill
03-16-2003, 09:32 PM
Try this:

else if (form.newPASS2.value != form.newPASS.value){
//passwords don't match...
}

DanUK
03-16-2003, 09:36 PM
thanks that works..

but how can i get it so it comes up with a query saying that the passwords are incorrect?

thanks for your help again.

AdamBrill
03-16-2003, 09:40 PM
umm... It should work if you do it the same way you did the other ones. Like this:

else if (form.newPASS2.value != form.newPASS.value){
alert("The passwords don't match");
}

One thing is if this is a form validator, then make sure you put return false; in there. Otherwise it will submit the form anyway...

DanUK
03-16-2003, 09:44 PM
brilliant that works great, thanks!

now i'm pushing my luck but hehehe i'll ask anyway.
Is there a way to make sure the passwords entered do not match another form i have, which is form.newUser - the passwords cannot be the same as the username for my database (a gaming clan).
So basically - if the passwords entered are the same as the 'newUser' form it would come up an alert to say 'Your password cannot be the same as your user'.

Is this possible? If not thank you very much for your previous help!

AdamBrill
03-16-2003, 09:50 PM
Try this:

else if (form.newPASS2.value != form.newPASS.value){
alert("The passwords don't match");
}else if(form.newPASS2.value != form.otherInputName.value){
alert("The password is the same as the username.");
}

Let me know if you have any more problems. ;)

DanUK
03-16-2003, 09:54 PM
yayyyy thank you so much adam !!!

seeming as you're good at this, I asked a question in a help channel for javascript and they didn't know the answer.
If you have a form with data already inserted, i.e I have a 'survey' on my site - which asks general usaeg, so I have initial values of say:

Sunday:
Monday:
Tuesday:
Wednesday:
Thursday
Friday:
Saturday:

what would my verify become?

generally i'm using something like ..

else if (form.genUSAGE.value =="") {
alert("Please enter your general usage");
form.genUSAGE.select(); }

how could i enter those initial values and still make sure the visitor fills it in? i've tried loads of ways but never suceeded, also how to make the inital values 'permanent' so they cannot be deleted by the visitor. Any help you can give on this is much appreciated, and i'll also pass it on so the help channel on chat will know too .. thanks.

AdamBrill
03-16-2003, 10:15 PM
So, for the first one, you want to be Sunday: and then something else? Is that right? If so, then try this:

else if(!/^Sunday:.+/i.test(form.genUSAGE.value)){
alert("Please enter more data...");
}

Right now it is NOT case sensative. If you want it to have to have a capital S, then do this:

else if(!/^Sunday:.+/.test(form.genUSAGE.value)){
alert("Please enter more data...");
}

Notice the i is gone after the /. As for making it so they can't change the beginning part, try this:

else if(!/^Sunday:/i.test(form.genUSAGE.value)){
form.genUSAGE.value="Sunday:"+form.genUSAGE.value;
}
That is about as close as that can come... However, I would suggest that you put it outside the input field. So it looks something like this:

Sunday:<input type=text>

Then, if you want the Sunday: part in there when you submit it, you can add it like this:

form.genUSAGE.value="Sunday:"+form.genUSAGE.value;

Hopefully one of those will work for you. :)

DanUK
03-16-2003, 10:17 PM
Great, you're a star - thanks!