admin管理员组文章数量:1388134
How can i add php content or php variable inside Java-script alert box?! I tried to make it work few ways but it is only popping up a blank box rather than the contents of php variable.
Here is the code:
<script language="javascript">
$(document).ready(function() {
$("#a").blur(function() {
<?php $b = $_POST['a'];
if(isset($_POST['update'])) {
mysql_query("UPDATE tbl_travel set fld_a='".$_POST[$b]."' where fld_id = '".$_POST["id"]."' ") or die(mysql_error());
} ?>
alert (<?php $b ?>);
});
});
</script>
Thank You for your Help :)
How can i add php content or php variable inside Java-script alert box?! I tried to make it work few ways but it is only popping up a blank box rather than the contents of php variable.
Here is the code:
<script language="javascript">
$(document).ready(function() {
$("#a").blur(function() {
<?php $b = $_POST['a'];
if(isset($_POST['update'])) {
mysql_query("UPDATE tbl_travel set fld_a='".$_POST[$b]."' where fld_id = '".$_POST["id"]."' ") or die(mysql_error());
} ?>
alert (<?php $b ?>);
});
});
</script>
Thank You for your Help :)
Share Improve this question asked Sep 7, 2013 at 9:57 PoojaPooja 1701 gold badge1 silver badge10 bronze badges 6 | Show 1 more comment5 Answers
Reset to default 8Change this
alert (<?php $b ?>);
to this
alert ('<?php echo $b; ?>');
You need to output the value of $b
and add quotes inside the alert.
About PHP - echo
Have you tried this?
alert ('<?php echo $b ?>');
I use it like this
$text="Example PHP Variable Message";
echo '<script type="text/javascript">alert("'.$text.'")</script>';
1.
<script>
alert("</script><?php $r=5;echo $r;?> <script>")
</script>
you have to script off on when php start
This worked for me :
alert ("<?php echo $b; ?>");
本文标签:
版权声明:本文标题:How to add php content or variable inside javascript alert box?! javascript, php, alertbox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739248225a2154788.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
alert(<?php print($b); ?>);
will do – Shankar Narayana Damodaran Commented Sep 7, 2013 at 10:00