Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  10] [ 7]  / answers: 1 / hits: 15747  / 11 Years ago, tue, november 5, 2013, 12:00:00

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 comes 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?


More From » php

 Answers
9

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 comparison (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; ?>

[#74510] Sunday, November 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
citlalia

Total Points: 138
Total Questions: 104
Total Answers: 87

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;