Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  51] [ 2]  / answers: 1 / hits: 48935  / 11 Years ago, sat, september 7, 2013, 12:00:00

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 :)


More From » php

 Answers
8

Change 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


[#75841] Thursday, September 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Sun, Aug 15, 21, 00:00, 3 Years ago
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
;