title: How to pass loop value from hidden input field within select form to Ajax
body: <p>I thought this would be simple? </p>
  
  <p>I have a select form with a hidden input field to carry a looped ID. I wish to pass both the selected option VALUE and the hidden input field VALUE to Ajax Function.</p>
  
  <p>When I place <code>value='$id_static[$k]'</code> as an option in the select field the Id loops properly.</p>
  
  <p>when I pass as value in the hidden input it only passes '1' regardless of row selected.</p>
  
  <p>See condensed code below.</p>
  
  <pre><code>  &lt;form&gt;
         &lt;div class='select-style'&gt;
    &lt;select  onChange='update(this.value)' id='gcc' name='gcc' class='form-control'&gt;                        
          &lt;option value='i2000'&gt;i 2000&lt;/option&gt;
          &lt;option value='$id_static[$k]'&gt;i 3000&lt;/option&gt;
          &lt;option value='i4000'&gt;i 4000&lt;/option&gt;
    &lt;/select&gt;  
        &lt;input  type='hidden'  id='g' name='g' value='$id_static[$k]'&gt;
    &lt;/div&gt;           
    &lt;/form&gt;
  </code></pre>
  
  <p>Notice how i have $id_static[$k] as value in one of my Select options. I used as testing only... Ajax processes loop perfectly. problem is i need it in my hidden field.</p>
  
  <p>Here is my loop in case you need to see it</p>
  
  <pre><code>  while ($stmt-&gt;fetch()){
        $id_static[] = $id_ai;      
        foreach($id_static as $k =&gt; $v){    
     } 
  </code></pre>
  
  <p>Below is my JQuery Ajax: Code</p>
  
  <pre><code>  &lt;script&gt;
      function update(gcc , g) {
        var idgap = $('#g').val();           
               jQuery.ajax({                   
                  type: 'POST',
                   url: 'gap2.php',
                   dataType: 'json',
                   data:  {  gcc : gcc , idgap : idgap } ,                    
                   success: function(response){                
                   console.log(response);                     
                   jQuery('.response').html(response);                    
                  }
             });     
          } 
       &lt;/script&gt;
  </code></pre>
  
  <p>Ok what I've done in the Interim. Combined my values to 1 with a <code>,</code> separating <code>&lt;Select&gt;&lt;option value='i3000,$id_static[$k]'&gt;i3000&lt;/option&gt;</code> and split value in my PHP as below.</p>
  
  <pre><code>    $str = $_POST['gcc'];
      $split = explode("," , $str);
  
      $gcc =   $split[0];
      $g = $split[1];
  </code></pre>
  
  <p>Must be a better way to use AJAX for loops. My only goal is to make changes to PAGE without refreshing PAGE. Next issue is taking PHP result <code>echo</code> to ajax without changing <code>&lt;div&gt;</code> for each row. </p>