title: Laravel get the value of dynamic radio button in jquery created with for loop
body: <p>I have a form in my view where I have populated some dynamic radio buttons using data from the database. Code looks like this-</p>
  
  <pre><code>&lt;div class="row"&gt;
  @foreach($status as $s)
      &lt;div class="col-md-6"&gt;
          &lt;label class="custom-control custom-radio"&gt;
              &lt;input id="status" name="status" value="{{$s-&gt;id}}" type="radio" class="custom-control-input"&gt;
              &lt;span class="custom-control-indicator"&gt;&lt;/span&gt;
              &lt;span id="status-name" class="custom-control-description"&gt;
                  {{$s-&gt;specification}}
              &lt;/span&gt;
          &lt;/label&gt;
      &lt;/div&gt;
  @endforeach
  &lt;/div
  </code></pre>
  
  <p>and in HTML-</p>
  
  <pre><code> &lt;div class="col-md-6"&gt;
      &lt;label class="custom-control custom-radio"&gt;
          &lt;input id="status" name="status" value="1" type="radio" class="custom-control-input"&gt;
          &lt;span class="custom-control-indicator"&gt;&lt;/span&gt;
          &lt;span id="status-name" class="custom-control-description"&gt;Yes&lt;/span&gt;
      &lt;/label&gt;
  &lt;/div&gt;                                  
  </code></pre>
  
  <p>
          
              
              
              
                 Yes
              
          
      
      
          
             
             
             
                 Yes
             
          
      </p>
  
  <p>Now I want to send it to controller through ajax.I have tried this-</p>
  
  <pre><code>var status = document.getElementsByName('status').value;
  if(status) {
      $.ajax({
         url: '/getpriceajax'+'/'+status,
         type: "GET",
         dataType: "json",
         success:function(data) {
             $('#calculated_price').val(data[0]);
             document.getElementById("price-show").innerHTML = "Product price is "+ data[0]+"and "+data[1];           
             $(".phone-value-details").slideDown(700);
             return false;
         }
     });
  }else{
  
  }
  </code></pre>
  
  <p>But it is always sending the value of the first radio button whether it is selected it or not. I have realized that it is happening because two radio buttons have the same name and by default, jquery is taking the first one. So, I think of renaming them dynamically. like-</p>
  
  <pre><code>name="status_{{$s-&gt;id}}"
  </code></pre>
  
  <p>But I don't know how to access this dynamic name or id in Jquery.</p>