Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a JS variable inside php code?
    primarykey
    data
    text
    <p>I'm attempting to make it so that when you click a button, it'll add new fields to the page. I know that onclick can only take JS functions so I decided to try my luck making a JS script. At first I had tried to do</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;multiple line test&lt;/title&gt;&lt;head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; var texters=''; var num=0; function newInput(nomnom) { texters=''; num=nomnom+1; for (var i=0; i&lt;nomnom; i++) { texters+='&lt;p&gt;\ Please specify a file, or a set of files:&lt;br&gt;\ &lt;input type="file" size="40"&gt;\ &lt;/p&gt;\ &lt;p&gt;\ Caption : &lt;br&gt; \ &lt;input type="text" size="30"&gt;\ &lt;/p&gt;';\ } document.write(texters+'&lt;div&gt;\ &lt;input type="submit" value="Send"&gt;\ &lt;/div&gt;\ &lt;/form&gt;\ &lt;br&gt;' + '&lt;input type="button" value="new entry" onclick="newInput(num)"&gt;' . '&lt;/body&gt;&lt;/html&gt;'); } newInput(num); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>but that didn't work. So I tried instead to add a little bit of php being that I know it better. I tried this : </p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;multiple line test&lt;/title&gt;&lt;head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; var texters=''; var num=0; function newInput(nomnom) { document.write(&lt;?php tex=''; for (var i=0; i&lt;=(nomnom); i++) { tex.='&lt;p&gt; Please specify a file, or a set of files:&lt;br&gt; &lt;input type="file" size="40"&gt; &lt;/p&gt; &lt;p&gt; Caption : &lt;br&gt; &lt;input type="text" size="30"&gt; &lt;/p&gt;'; } echo tex . '&lt;div&gt; &lt;input type="submit" value="Send"&gt; &lt;/div&gt; &lt;/form&gt; &lt;br&gt;' . '&lt;input type="button" value="new entry" onclick="newInput(num)"&gt;' . '&lt;/body&gt;&lt;/html&gt;'; ?&gt;); } newInput(num); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>But I know that won't work because I can't get the variable I'm using for the number of fields to use out of the JS and into the PHP. Is there any way I could force JS to put that number in $_POST so I can retrieve it without having to make another form? Or is there a better way to do what I'm trying to do?</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.
 

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