0

hello I picked up a custom alert from the internet and would like to implement in my php echo alert, already tried several ways but I can not find the correct syntax. help please

I think I need to pass the "echo" to the javascript and call the function when you call the "echo" in PHP, but I'm not having any luck

  <script>
  function CustomAlert(){
this.render = function(){
    var winW =  window.innerWidth;
    var winH = window.innerHeight;
    var dialogoverlay = document.getElementById('dialogoverlay');
    var dialogbox = document.getElementById('dialogbox');
    dialogoverlay.style.display = "block";
    dialogoverlay.style.height = winH+"px";
    dialogbox.style.left = "20px";
    dialogbox.style.top = "70px";
    dialogbox.style.display = "block";
    document.getElementById('dialogboxhead').innerHTML = "Login Processado com Sucesso";
    document.getElementById('dialogboxbody').innerHTML = "Seja Bem Vindo";
    document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>';


}
this.ok = function(){
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";

}
}
var Alert = new CustomAlert();

</script>

and php:

   <?php
  $email=$_POST['email'];
  $senha=$_POST['senha'];
  $sql = mysql_query("SELECT email, senha FROM clientes WHERE email = '$email' and senha = '$senha'") or die(mysql_error());
  $row = mysql_num_rows($sql);
  if($row > 0 ) {
session_start();
$_SESSION['email']=$_POST['email'];
$_SESSION['senha']=$_POST['senha'];
echo '<script>';
echo 'Alert.render("Login efetuado com sucesso")';
echo '</script>';
echo "<script>loginsucessfully()</script>";


    } else {
echo "Usuario ou senha invalidos";
echo "<script>loginfailed()</script>";
    }

   ?>
1
  • I need call the var Alert.render on my PHP echo Commented Apr 2, 2014 at 23:28

2 Answers 2

2

To pass a variable from PHP to Javascript:

var something = <?php echo $something; ?>;

As a side note, the semicolon in the PHP tags isn't necessary since it's only one line of code; it's just a matter of style.

Sign up to request clarification or add additional context in comments.

8 Comments

ok thanks, but how to Javascript to PHP, i just need when my user login sucessfully show this custom alert.. can you show me how ? please
ok but i've declared var Alert = CustomAlert(); how i can pass this var Alert to echo on php, like var Alert = (CustomAlert() + <?php echo $something; ?>; i cant figure it out
Are you just trying to display a simple JS alert? If so, you can use alert(<?php echo $something; ?>);.
trying to use my custom alert js on php echo alert .. what i dont understand is how echo an JS var, but the var calls a function so i cant use var something = <?php echo $something; ?>;
I need call the var Alert.render on my PHP echo
|
1

To do this you can either program a javascript function that submits a form - or you can use ajax / jquery. jQuery.post

Or maybe this can help you .

<script type="text/javascript">
  var foo = '<?php echo $foo ?>';
</script>

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.