Get data written in certain text area
P粉713866425
2023-08-17 21:56:30
<p>I have to generate a report from different information in a form.</p>
<p>首先,我必须从这里选择一种物质:</p>
<pre class="brush:php;toolbar:false;"><input type="checkbox" class="sostanzeCheck" value="Cocaina" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Cocaina </span><br>
<input type="checkbox" class="sostanzeCheck" value="Crack" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Crack </span><br>
<input type="checkbox" class="sostanzeCheck" value="Marijuana" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Marijuana </span><br>
<input type="checkbox" class="sostanzeCheck" value="Cannabis" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Cannabis </span><br>
<input type="checkbox" class="sostanzeCheck" value="Eroina" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Eroina </span><br>
<input type="checkbox" class="sostanzeCheck" value="Skunk" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Skunk </span><br>
<input type="checkbox" class="sostanzeCheck" value="Sintetiche" name="sostanza[]" onchange="collectSostanze()"/><span class="testoBianco"> Sintetiche </span><br><br></pre>
<p>我已经写了一个函数,它会将我选择的内容打印到控制台,以验证是否正确,函数如下:</p>
<pre class="brush:php;toolbar:false;">function collectSostanze(){
const selectedSostanze = [];
const checkboxes = document.querySelectorAll('.sostanzeCheck:checked');
checkboxes.forEach(checkbox => {
selectedSostanze.push(checkbox.value);
console.log("Sostanza: ", selectedSostanze);
});
return selectedSostanze;
}</pre>
<p>Now, I'm running into a problem that doesn't collect what I type in these text areas: </p>
<pre class="brush:php;toolbar:false;"><div id="bloccoAnalisi" style="display: none;">
<label>Percentuale di Principio Psicoattivo</label><br>
<textarea rows="3" cols="80" class="textarea" name="psicoattivo" id="psicoattivo_text" ></textarea><br>
<label>Grammi</label><br>
<textarea rows="3" cols="80" class="textarea" name="grammi" id="grammi_text" ></textarea>
<label>Dosi Medie Singole</label><br>
<textarea rows="3" cols="80" class="textarea" name="dosi" id="dosi_text" ></textarea>
</div><br></pre>
<p>The values change in real time and what I want to achieve is to generate the following report: </p>
<p>"I am satisfied with my success and my success with "SUBSTANCE_NAME" with THC pari al "FIRST TEXTAREA'S VALUE%" and "SECOND TEXTAREA'S VALUE%" per complessi "SECOND TEXTAREA'S VALUE" da cui era possibile ricavare circa "THIRD TEXTAREA'S VALUE" dosi medie singole".</p>
<p>The report must be added to another text area like this: </p>
<pre class="brush:php;toolbar:false;"><div id="paragrafiRicostruzione" class="paragrafoFields">
<h3>Ricostruzione del Fatto</h3>
<textarea rows="3" cols="80" class="textarea" id="reportTextArea" name="report"></textarea>
</div></pre>
<p>Of course, I have to generate different reports based on the substances I choose and append them together one by one. </p>
<p>I am using Laravel framework and scripting using JS. </p>
<p>Thank you. </p>
You can listen to the keyup event on the form. This event will occur whenever the user types in the text area. The entire (template) string is then inserted into the value of the report text area.