1

let's say i have an input form, wherein, it's use for an email 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");
1
  • try <script type="text/javascript">alert('<?php echo $errorMessage ?>')</script> Where echo $errorMessage is your dynamic php errormessage Commented Jul 29, 2011 at 10:13

3 Answers 3

5

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");
Sign up to request clarification or add additional context in comments.

1 Comment

2

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.

1 Comment

the problem with ajax in jquery,is, i dunno how to use it...i hafta to learn it over the weekend, as of now,i just wanted to make the form work with an alert box :(
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.