title: How to get a variable from JavaScript to ColdFusion
body: <p>I'm currently working on one issue and I need some help. I'm working on HTML code that fills in special machine labels. It is a kind of web page on where people fill in the number of lines and text size, then enter the text of the lines they want the resulting table to contain in each line.</p>
  <p><strong>I need advice on how to save JavaScript variable to cf variable.</strong> We use ColdFusion to link the code to DB.</p>
  <p>Here is a small sample of the problem.</p>
  <pre><code>for(let a = 1; a &lt;= g_rowCounter; a++){
      text = getVal('i_row-input_' + a);
      g_texts.push(text);
  }
  </code></pre>
  <p>Is there anyone who would encounter a similar problem or know how to solve it?</p>
  <p><strong>Thank you for all the answers.</strong></p>
  <p>Here is for reference whole code to lock at the problem.</p>
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset=&quot;UTF-8&quot;&gt;
          &lt;title&gt;Stitek&lt;/title&gt;
          
          &lt;script&gt;
              var g_rowCounter = 0;
              var g_texts = [];
              
              function vygenerujInputy(){
                  var rowCount = parseInt(getVal('i_row-count'));
                  var inputWrp = byId('i_row-inputs_wrp');
                  var oneInput = null;
                  
                  inputWrp.innerHTML = '';
                  
                  for(let a = 1; a &lt;= rowCount; a++){
                      var defText = '';
                      if(g_texts[a - 1]){
                          defText = g_texts[a - 1];
                      }
                      
                      oneInput = createRowInput(a, defText);
  
                      inputWrp.appendChild(oneInput);
                  }
                  
                  g_rowCounter = rowCount;
              }
  
              function createRowInput(number, defText){
                  var r = document.createElement('div');
                  
                  var input = document.createElement('input');
                  input.setAttribute('id', 'i_row-input_' + number);
                  input.setAttribute('class', 'c_row-input');
                  input.value = defText;
                  
                  var numberSpan = document.createElement('span');
                  numberSpan.innerHTML = number + ')&amp;nbsp;&amp;nbsp;';
                  
                  r.appendChild(numberSpan);
                  r.appendChild(input);
                  
                  return r;
              }
              
              function getVal(htmlId){
                  var r = byId(htmlId).value;
                  return r;
              }
  
              function byId(htmlId){
                  var r = document.getElementById(htmlId);
                  return r;
              }
              
              function VygenerujVystup(){
                  
              }
  
              function vygenerujTabulku(){
                  var outputWrp = byId('i_vystupni-div');
                  outputWrp.innerHTML = '';
  
                  if(g_rowCounter &lt; 1){
                      window.alert('nejprve zvol počet řádků');
                  } else {
                      var textSize = parseInt(getVal('i_velikost-textu'));
                      
                      if(textSize &lt; 6 || textSize &gt; 75){
                          window.alert('velikost textu musi byt v intervalu od 6 do 75 mm');
                      } else {
                          var frameSize = parseInt(getVal('i_sirka-ramecku'));
                          
                          /*
                          if(frameSize &lt; 1){
                              window.alert('sirka ramecku musi byt vetsi nez 0');
                          } else {
                              outputWrp.style.width = frameSize + 'px';
                          */   
                              g_texts = [];
  
                              var text = '';
                              var oneRowDom = null;
  
                              for(let a = 1; a &lt;= g_rowCounter; a++){
                                  text = getVal('i_row-input_' + a);
                                  g_texts.push(text);
                              }
  
                              
  
                              for(let a = 0; a &lt; g_texts.length; a++){
                                  oneRowDom = createWrappedSpan('jeden-radek', g_texts[a], textSize);
                                  outputWrp.appendChild(oneRowDom);
                              }    
                         // }  
                      }
                  }
              }
  
              //kdyz textSize je vetsi nez 0, nastavi se velikost textu podle tohoto cisla. jinak se necha vychozi velikost
              function createWrappedSpan(rawClassName, text, textSize){
                  var r = document.createElement('div');
                  r.setAttribute('class', 'c_' + rawClassName + '_wrp');
  
                  var span = document.createElement('span');
                  span.setAttribute('class', 'c_' + rawClassName + '_text');
                  span.innerHTML = text;
  
                  if(textSize &gt; 0){
                      span.style.fontSize = textSize + 'px';
                  }
                  
                  r.appendChild(span);
  
                  return r;
              }
          &lt;/script&gt;
      &lt;/head&gt;
      
      &lt;body&gt;
  
        &lt;cfform&gt;
          &lt;b&gt;Zvol počet řádků štítku &amp;nbsp;&amp;nbsp;&lt;/b&gt;
      
          &lt;cfselect name=&quot;srows&quot; id=&quot;i_row-count&quot; onchange=&quot;vygenerujInputy()&quot;&gt;
              &lt;option value=&quot;0&quot; name=&quot;m00&quot; size=&quot;50&quot; maxlength=&quot;30&quot; type=&quot;text&quot;&gt;0    
              &lt;option value=&quot;1&quot; name=&quot;m01&quot; size=&quot;50&quot; maxlength=&quot;30&quot; type=&quot;text&quot;&gt;1
              &lt;option value=&quot;2&quot; name=&quot;m02&quot; size=&quot;50&quot; maxlength=&quot;30&quot; type=&quot;text&quot;&gt;2
              &lt;option value=&quot;3&quot; name=&quot;m03&quot; size=&quot;50&quot; maxlength=&quot;30&quot; type=&quot;text&quot;&gt;3
              &lt;option value=&quot;4&quot; name=&quot;m04&quot; size=&quot;50&quot; maxlength=&quot;30&quot; type=&quot;text&quot;&gt;4
              &lt;option value=&quot;5&quot; name=&quot;m05&quot; size=&quot;50&quot; maxlength=&quot;30&quot; type=&quot;text&quot;&gt;5
          &lt;/cfselect&gt;
        
          &lt;!--
              Výběr hodnot - počtu řádků - 1 - 5.
          --&gt;
          &lt;br&gt;&lt;br&gt;
          &lt;div id=&quot;i_row-inputs_wrp&quot; class=&quot;c_row-inputs_wrp&quot;&gt;&lt;/div&gt;
          &lt;br&gt;
          &lt;span&gt;velikost textu (milimetry)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;cfinput type=&quot;number&quot; name=&quot;quantity&quot; id=&quot;i_velikost-textu&quot; min=&quot;6&quot; max=&quot;75&quot; range = &quot;6,75&quot; validate = &quot;integer&quot;&gt;
          &lt;br&gt;
          &lt;!--
              Velikost textu je omezena od 6ti do 75ti.
          --&gt;
          
        &lt;/cfform&gt;
          
          &lt;br&gt;
          &lt;button onclick=&quot;vygenerujTabulku()&quot; class=&quot;c_form-button&quot;&gt;Náhled štítku&lt;/button&gt;
          &lt;br&gt;
  
          &lt;div class=&quot;c_vystup_wrp&quot; id=&quot;i_vystupni-div&quot;&gt;
          
          &lt;/div&gt;
          
        &lt;cfform&gt;
        
          &lt;cfset pr1 = &quot;input1&quot;&gt;
          &lt;cfset pr2 = &quot;input2&quot;&gt;
          &lt;cfset pr3 = &quot;input3&quot;&gt;
          &lt;cfset pr4 = &quot;input4&quot;&gt;
          &lt;cfset pr5 = &quot;input5&quot;&gt;
        &lt;cfset pr6 = &quot;vyska&quot;&gt;
        &lt;cfset pr7 = &quot;sirka&quot;&gt;
        
        &lt;cfoutput&gt;#pr1#&lt;br&gt;#pr2#&lt;br&gt;#pr3#&lt;br&gt;#pr4#&lt;br&gt;#pr5#&lt;br&gt;#pr6#&lt;br&gt;#pr7#&lt;br&gt;&lt;/cfoutput&gt;
          
          &lt;cfselect name=&quot;swidth&quot; id=&quot;i_sirka-ramecku&quot; onchange=&quot;vygenerujTabulku()&quot;&gt;    
          &lt;/cfselect&gt;
        &lt;/cfform&gt;
      
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>