开发者

how to add a javascript alert with a PHP script?

开发者 https://www.devze.com 2023-03-23 23:12 出处:网络
let\'s say i have an input form, wherein, it\'s use for an ema开发者_开发技巧il address. this form is part of a long form so i use an alert box instead when other inputs got errors....my question now

let's say i have an input form, wherein, it's use for an ema开发者_开发技巧il address. this form is part of a long form so i use an alert box instead when other inputs got errors....my question now is, if I checked the email input string via php, if it has been taken , how will I put the message like e.g "this email has been taken" in an alert box if i am using PHP to check it from backend ?..i want an alert box, since I use it with the other input boxes that don't need a backend check e.g

alert("$errormessage");


PHP is server-side language. you can output it to user with

echo "<script>alert('".mysql_real_escape_string($errormessage)."');</script>";

or you can write your own function

function alert($a){
    echo "<script>alert('".mysql_real_escape_string($a)."');</script>";

}

alert("test");


You can echo any kind of javascript with PHP. The question is however, are you sure you want to do this? You can also do like this:

<?php if(emailExists): ?>
<script>alert('Email exists!')</script>
<?php endif; ?>

But you could also use jQuery and Ajax requests to check if email exists with ajax when user has typed the email.


echo '<script>alert("ssss");</script>' ; just put it within echo it will work that way

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号