User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Javascript pop-up alert question Page [1]  
mytwocents
All American
20654 Posts
user info
edit post

I have a form in which a user is asked to input their email address...and then asked to input the address again right below it and I want a popup alert that won't allow for the addresses to be different...And I already have a form validation checking to see if all required fields on the entire form are filled out so this would be just for the email address. ???

1/15/2006 4:24:27 PM

BigMan157
no u
103354 Posts
user info
edit post

if(document.form.email1.value!=document.form.email2.value) {
alert("n00b");
document.form.email1.value= "";
document.form.email2.value="";
}

[Edited on January 15, 2006 at 7:42 PM. Reason : like that?]

1/15/2006 7:23:04 PM

mytwocents
All American
20654 Posts
user info
edit post

well...the thing is that wouldn't there need to be a 'submit' button or something to call that function? and if so, that wouldn't work because they don't submit the form until the very end of the form... is there such a way to make an onFocus event so that after they re-enter their email if it doesn't match then the alert comes up otherwise it just lets it go?

1/17/2006 4:17:37 PM

Noen
All American
31346 Posts
user info
edit post

use the onBlur event to call your javascript function

1/17/2006 4:25:24 PM

mytwocents
All American
20654 Posts
user info
edit post

Now THAT'S funny.... onBlur!!!

But really, Ima try it....

1/17/2006 4:50:18 PM

mytwocents
All American
20654 Posts
user info
edit post

ok...so then how would I change the code to say something like:


function valid(form){
var input1=email address entered in the first box;
input=document.myform.data.value;
if (input2==input1){
alert("Please enter the same address");
}
}
I know it's messy...and I know somewhere I'd have to say basically that if email1 does not equal email2, then popup the alert, else nothing...but I'm confusing myself and now I'm totally lost

[Edited on January 17, 2006 at 5:24 PM. Reason : ]

1/17/2006 5:23:30 PM

mytwocents
All American
20654 Posts
user info
edit post

OK...I got this far, and it works fine if it's on it's own page...but the minute I put it on the page with the other items, I'm getting an error?

<SCRIPT LANGUAGE="JavaScript">
function valid(form){
var input1=document.myform.email1.value;
var input2=document.myform.email2.value;
if (input2!==input1){
alert("Please enter the same address");
}
}
</SCRIPT>





[Edited on January 17, 2006 at 5:52 PM. Reason : ]

1/17/2006 5:51:31 PM

BigMan157
no u
103354 Posts
user info
edit post

^the '!==' should be '!='

if you have your two boxes like

Email 1: <input type='text' name='email1'><br>
<input type='text' name='email2' onBlur='valid()'>


have this code up in your header

<script>
function valid() {
if (document.myform.email1.value!=document.myform.email2.value){
alert("Please enter the same address");
document.myform.email1.value="";
document.myform.email2.value="";
}
}
</script>


onBlur means it'll do it once that element is deselected

course that code above would only work if the user filled the elements out in order, otherwise i'd fuckup


[Edited on January 17, 2006 at 5:58 PM. Reason : and if you are using more than one form, remember to use the right name]

1/17/2006 5:54:52 PM

mytwocents
All American
20654 Posts
user info
edit post

damn it...I'm still getting an error message...., it's telling me that document.form.email1 is null or not an object

1/17/2006 6:06:15 PM

BigMan157
no u
103354 Posts
user info
edit post

did you name the form?

just go off of this: http://www.codelifter.com/main/javascript/emailaddresschecker1.html

[Edited on January 17, 2006 at 6:36 PM. Reason : yep]

1/17/2006 6:29:45 PM

mytwocents
All American
20654 Posts
user info
edit post

mother fucker kJ FhkJhfkjS fhkjf hkjsdh;SHdf

1/17/2006 8:24:24 PM

mytwocents
All American
20654 Posts
user info
edit post

ok...maybe the problem is that I have a form within a form...which according to some things I've read...you can't have that... is there any other way to have an onBlur event without it being a form? And I mean it would actually have to do the checking of the data and everything...so does this mean I'm SOL?

1/17/2006 8:34:14 PM

BigMan157
no u
103354 Posts
user info
edit post

why do you need a form within a form?

1/17/2006 8:35:05 PM

mytwocents
All American
20654 Posts
user info
edit post

because I have form with many questions on it...some are required, other's not... and IN the form, when it asks for a person's email address, I want them to reenter it twice (like a confirmation sorta) and if it doesn't match, then it pops up with the alert..... so the alert just applies to the one item, email address..

1/17/2006 8:40:42 PM

BigMan157
no u
103354 Posts
user info
edit post

i'd just put everything in the one form

the alert can only pop up when the verify function is called, and since the email thing is the only thing calling it, it shouldn't be a problem

1/17/2006 9:01:39 PM

mytwocents
All American
20654 Posts
user info
edit post

Bigman...I don't know how, but I somehow got it to work by just using the one form like you said and verifying it.

THANK YOU THANK YOU THANK YOU

1/18/2006 1:40:00 PM

 Message Boards » Tech Talk » Javascript pop-up alert question Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.