Reputation: 141
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>";
}
?>
Upvotes: 0
Views: 782
Reputation: 1262
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.
Upvotes: 2
Reputation: 84
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>
Upvotes: 1