Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How can I add an *alert* popup to an existing "IF" statement?
Old 01-10-2007, 11:57 PM How can I add an *alert* popup to an existing "IF" statement?
Average Talker

Posts: 20
Name: Chris
Trades: 0
I've got this mailing list app (php/mysql) that I'm working into my website and I've got it up and running and now I'm trying to make a couple modifications to the existing code.

As far as I understand the code, when someone submits an email address via the <form> tag, the script runs a javascript to check whether the email addres is composed of valid characters or if it's already in the database before processing the submission. What I want to do is configure the script so that upon a successful submission an alert box pops up with a little "thank you" message (or whatever, you get the idea ).

The existing code already throws up an alert box if the email address' format is invalid. I think the code is in here that I want to mess with, but I'm not sure where exact because I don't really know javascript.

Code:
           <script language=JavaScript type=text/javascript>
function checkNEmail(form) {
    if (isBlank(form.email.value) || isBlank(form.name.value) || !isEmailValid(form.email.value) ) 
    {
        alert("Please enter a valid Name and  Email Address .\nThe email or name you have typed in does not appear to be valid.");
        form.email.focus();
        return false;
    }
    }

function checkEmail(form) {
    if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
        alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
        form.email.focus();
        return false;
    }
return true;

}

function isBlank(fieldValue) {
    var blankSpaces = / /g;
    fieldValue = fieldValue.replace(blankSpaces, "");
    return (fieldValue == "") ? true : false;
}

function isEmailValid(fieldValue) {
    var emailFilter = /^.+@.+\..{2,4}$/;
    var atSignFound = 0;
    for (var i = 0; i <= fieldValue.length; i++)
        if ( fieldValue.charAt(i) == "@" )
            atSignFound++;
    if ( atSignFound > 1 )
        return false;
    else
        return ( emailFilter.test(fieldValue) && !doesEmailHaveInvalidChar(fieldValue) ) ? true : false;
}

function doesEmailHaveInvalidChar(fieldValue) {
    var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\] ]/;
    return ( illegalChars.test(fieldValue) ) ? true : false;
}
</script>
I'm not sure if this next part helps at all, but if the email turns out valid and is not already in the database, then it seems that the file email_not_exist.php is called which contains this:
Code:
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td width="38%"><div align="center">Removal Error !!!</div></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td><div align="center"> <?php echo str_replace("{email}",$email,$lang_emailexist_adress_error); ?></div></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
</table>
Thanks a lot for any ideas you all might have and I'm happy to give any more information that might help.
toastysquirrel is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-11-2007, 02:02 AM Re: How can I add an *alert* popup to an existing "IF" statement?
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
Just change your function checkEmail() to this:
Code:
function checkEmail(form) {
    if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
        alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
        form.email.focus();
        return false;
    }
    else {
        alert("Thank you!");
        return true;
    }
}
Oneway is offline
Reply With Quote
View Public Profile
 
Old 01-11-2007, 12:22 PM Re: How can I add an *alert* popup to an existing "IF" statement?
Average Talker

Posts: 20
Name: Chris
Trades: 0
Thank you soooo much Oneway. I've posted in a ton of forums and so far everyone just keeps saying, "why don't you do this instead, or why have it reload on the same page, or why are you using so many <div>s..." If I coded then script myself I wouldn't be asking this question in the first place. I get they're trying to be helpful in their own ways but I just want to get the site done

Thanks again man, that totally did it.

Actually, I did have a follow up question: Is there any other popup that can be used in this instance since I just noticed that the "alert" with the "!" icon doesn't exactly instill a sense of calm when I'm trying to "thank" someone. Something along the lines of the little alert window without the caution symbol?
toastysquirrel is offline
Reply With Quote
View Public Profile
 
Old 01-11-2007, 12:37 PM Re: How can I add an *alert* popup to an existing "IF" statement?
Oneway's Avatar
Skilled Talker

Posts: 71
Trades: 0
Let's see... There are confirm("message"); and prompt("message"); but those aren't really meant for just displaying a message.

Another option is to fake an alertbox by creating some html that looks like an alert box (which you can then customise to not show the exclamation mark.) I seem to remeber a good tutorial about it, but i can't find it anymore. You'll have to search on google a bit more than i did.
i used (javascript custom alert box) as keywords.
Oneway is offline
Reply With Quote
View Public Profile
 
Old 01-11-2007, 12:39 PM Re: How can I add an *alert* popup to an existing "IF" statement?
Average Talker

Posts: 20
Name: Chris
Trades: 0
Awesome, thanks for the lead! I'll see what I can turn up.
toastysquirrel is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How can I add an *alert* popup to an existing "IF" statement?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.71833 seconds with 12 queries