最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

echo php javascript alert? - Stack Overflow

programmeradmin1浏览0评论

How can I echo this javascript if the php error messages is called? I have an error message setting that when a user misses his username or password it triggers an error message. The php error message is called by a php code. Here is the code:

<?php echo showmessage($msg) ?> 

I have an alert message in javascript that when called it will make a javascript css pop up alert box. IF the javascript code is present it will show the alert box right away after reload. Here is code:

<script type="text/javascript">  
  $(document).ready(function () {  
   jqxAlert.alert('Alert Message');  
  })  
</script>  

How can I incorporate so that when the php echo message es up it will trigger the javscript alert message. I was trying an if in php, so something like this code:

if ( showmessage($msg) ) {
   <script type="text/javascript">  
     $(document).ready(function () {  
         jqxAlert.alert('Alert Message');  
     })  
   </script>
}

How can I echo my javascript message on the php call?

How can I echo this javascript if the php error messages is called? I have an error message setting that when a user misses his username or password it triggers an error message. The php error message is called by a php code. Here is the code:

<?php echo showmessage($msg) ?> 

I have an alert message in javascript that when called it will make a javascript css pop up alert box. IF the javascript code is present it will show the alert box right away after reload. Here is code:

<script type="text/javascript">  
  $(document).ready(function () {  
   jqxAlert.alert('Alert Message');  
  })  
</script>  

How can I incorporate so that when the php echo message es up it will trigger the javscript alert message. I was trying an if in php, so something like this code:

if ( showmessage($msg) ) {
   <script type="text/javascript">  
     $(document).ready(function () {  
         jqxAlert.alert('Alert Message');  
     })  
   </script>
}

How can I echo my javascript message on the php call?

Share Improve this question asked Nov 5, 2013 at 2:31 Anaes AriasAnaes Arias 491 gold badge1 silver badge5 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 1

This could be written like this:

endif

endif-stackoverflow

<?php if (showmessage($msg)): ?>
    <script>
        $(document).ready(function (){
            jqxAlert.alert('Alert Message');
        });
    </script> 
<?php endif; ?>

Or like this:

<?php if (showmessage($msg)) { ?>
    <script>
        $(document).ready(function (){
            jqxAlert.alert('Alert Message');
        });
    </script> 
<?php } ?>

Or like this:

<?php 

    if (showmessage($msg)) { 
        echo
        '
            <script>
                $(document).ready(function (){
                    jqxAlert.alert(\'Alert Message\');
                });
            </script> 
        ';
    } 

?>

short tags

short hand parison (ternary)

ternary 2

Or even this (probably not the best idea though):

<?= (showmessage($msg)) ? '<script>$(document).ready(function (){jqxAlert.alert(\'Alert Message\');});</script>' : ""; ?>

Alternatively, if you mean you would like to put the error message in that alertbox

<?php 

    if (showmessage($msg)) { 
        echo
        '
            <script>
                $(document).ready(function (){
                    jqxAlert.alert('.showmessage($msg).');
                });
            </script> 
        ';
    } 

?>

and again in the first style:

<?php if (showmessage($msg)): ?>
    <script>
        $(document).ready(function (){
            jqxAlert.alert(<?= showmessage($msg) ?>);
        });
    </script> 
<?php endif; ?>

something like this.. close your php tag before starting to write javascript..

<?php if ( showmessage($msg) ) { ?>
   <script type="text/javascript">  
       alert('Alert Message');
   </script>
<?php } ?>

Can you try this

     <?PHP if ( showmessage($msg) ) {  ?>
         <script type="text/javascript">
               $(document).ready(function () {
                   jqxAlert.alert('Alert Message');
                });
           </script> 
     <?PHP } ?>

You can create a function, I think this is the most practice way to do it:

1.define a function:

<?php function phpAlert($msg) {  echo '<script type="text/javascript">alert("' .$msg. '")</script>';}  ?>

2. call it like this:

<?php phpAlert(   "Hello world!\\n\\nPHP has got an Alert Box"   );  ?>
发布评论

评论列表(0)

  1. 暂无评论