Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How can I add an *alert* popup to an existing "IF" statement?

    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.

  • #2
    New Coder
    Join Date
    Nov 2004
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you put the code up on your site so we can see it in action?

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Someone dropped me this little bit of code that got my problem pretty much solved:
    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;
        }
    }
    Thanks for the help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •