Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP email validation function cannot echo JS alert?

if(isset($_POST['check'])){
    $email =  $_POST['email'];
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) { 
       echo '<script language="javascript">'; 
       echo 'alert(Valid email)';   
       echo '</script>';
    } else { 
       echo '<script language="javascript">'; 
       echo 'alert(Not valid email)';   
       echo '</script>';     
    }
}

i’m trying to show an alert with the result but it’s not working. however echo a text working but not JS alert.

why is that? is there another way to do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

put '<script type="application/javascript">'
instead of '<script language="javascript">'

yout script tag attribute is wrong and also you use alert function wrong.
change alert(Valid email) to alert("Valid email") and
change alert(Not valid email) to alert("Not valid email").

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading