Posts

Showing posts with the label Variables

Creating A Javascript Alert With Php That Has A Php Variable Inside?

Answer : You only forgot quotations that are required for the JavaScript alert. If you passed 'hello' to the function, your current code would create alert as: alert(hello) instead of doing: alert("hello") Therefore, change your line to the following (two double quotes are added before and after concatenating $error): echo '<script type="text/javascript">alert("'.$error.'");</script>'; and you can use your function: died('error on whatever'); Display variable php in alert javascript <?php function died($error) { ?> <script>alert("<?php echo $error; ?>")</script> <?php die(); } ?>

Concatenate A Dynamic Variable Name In Javascript

Answer : Not sure exactly what you are trying to accomplish, but with JavaScript, you could use the following: > var a = 1; > var b = {}; > b['fruit_' + a] = 'apple'; > b.fruit_1 "apple" > b['fruit_1'] "apple" You can do this by assigning the variable to a context. For example, to create a dynamically-named global variable in a browser context, you would use: const a = 1 window['fruit_' + a] = 'apple' console.log(fruit_1) If you're in a Node context, you would use global instead of window . If you were trying to create a variable in a method context, you would use this .

Add Php Variable Inside Echo Statement As Href Link Address?

Answer : Try like HTML in PHP : echo "<a href='".$link_address."'>Link</a>"; Or even you can try like echo "<a href='$link_address'>Link</a>"; Or you can use PHP in HTML like PHP in HTML : <a href="<?php echo $link_address;?>"> Link </a> you can either use echo '<a href="'.$link_address.'">Link</a>'; or echo "<a href=\"$link_address\">Link</a>'; if you use double quotes you can insert the variable into the string and it will be parsed. Basically like this, <?php $link = ""; // Link goes here! print "<a href="'.$link.'">Link</a>"; ?>