Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedding PHP within javascript
    primarykey
    data
    text
    <p>I'm trying to create a messaging system that opens when you click the "New Message" button. I'm using HTML, PHP, and javascript. </p> <p>I have a button set up with a container to append a textarea into. I am doing this with javascript DOM. This part I have no problem with, it is trying to get PHP inside javascript.</p> <p>So let's say I have a variable:</p> <pre><code>&lt;?php $my_name = "Eric" ?&gt; </code></pre> <p>Would I be able to call this in javascript? If not, are there any any other ways to approach this?</p> <p>Here is my full code:</p> <p>HTML:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;link type="text/css" rel="stylesheet" href="message.css"/&gt; &lt;script type="text/javascript" src="js/message.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;button id="new_message" onclick="createMessage()"&gt;New Message&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>CSS: </p> <pre><code>#container { position: absolute; height: 443px; width: 743px; border: 1px solid black; border-radius: 0 0 20px 0; margin-top: 100px; } </code></pre> <p>Javascript:</p> <pre><code>function createMessage() { var form = document.createElement("form"); form.name = "form_input"; form.method = "POST"; form.action = "messages.php"; container.appendChild(form); var textarea = document.createElement("textarea"); textarea.name = "message_input"; textarea.cols = 84; textarea.rows = 16; textarea.id = "message_input"; container.appendChild(textarea); }; </code></pre> <p>I'm trying to do something similar to Facebook, that when you click on the messages button, a pop up box appears with php inside of it. </p> <p>Can this be done the way I'm doing it with javascript or do I have to use something else? </p> <p>Thanks for your help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload