passing radio buttons from javascript to django views as a paramater
<p>I have a html page where I am passing the selected checkboxes to django views as parameter which works completely fine.</p>

<p>layout.html</p>

<pre><code>&lt;form action="{% url 'URL Which calls view' %}" method="post"&gt;
{% csrf_token %}
&lt;label class="checkbox"&gt;
  &lt;input type="checkbox" name="checks" value="REG_AGREED_SUITE01"&gt;REG_AGREED_SUITE01
  &lt;/label&gt;
   &lt;hr&gt;
  &lt;label class="checkbox"&gt;
  &lt;input type="checkbox" name="checks" value="REG_AGREED_SUITE02"&gt;REG_AGREED_SUITE02
  &lt;/label&gt;
   &lt;hr&gt;
  &lt;label class="checkbox"&gt;
  &lt;input type="checkbox" name="checks" value="REG_AGREED_SUITE03"&gt;REG_AGREED_SUITE03
  &lt;/label&gt;
   &lt;hr&gt;
</code></pre>

<p>form.py</p>

<pre><code>class NameForm(forms.Form):
</code></pre>

<p>views.py</p>

<pre><code>def view(request):
    if request.method == 'POST':
    form = NameForm(request.POST)
    else:
    form = NameForm()
    print request.POST.getlist('checks')

    form = NameForm(request.POST)
    list1 = request.POST.getlist('checks')
    TestSuite = ', '.join(list1)
</code></pre>

<p>Now I have a situation, Where I would like to pass the radio buttons as parameters in django views. I have a json file from which using java script I am pulling the values and displaying on html. Is there any way, when ever I select a radio button, I can pass them as a parameter in django views as above case? or is it the best approach to create a form in Django?</p>

<p>temp.json</p>

<pre><code>[
    {"STBStatus": "1", "RouterSNo": "R1", "STBLabel": "STB#1", "STBSno": "M11435TDS144"},
    {"STBStatus": "1", "RouterSNo": "R1", "STBLabel": "STB#2", "STBSno": "M11543TH4292"},
    {"STBStatus": "0", "RouterSNo": "R1", "STBLabel": "STB#3", "STBSno": "SN005"},
    {"STBStatus": "1", "RouterSNo": "R1", "STBLabel": "STB#4", "STBSno": "M11509TD9937"},
    {"STBStatus": "1", "RouterSNo": "R1", "STBLabel": "STB#5", "STBSno": "M11543TH4258"},
    {"STBStatus": "0", "RouterSNo": "R1", "STBLabel": "STB#6", "STBSno": "SN005"},
    {"STBStatus": "0", "RouterSNo": "R1", "STBLabel": "STB#7", "STBSno": "SN006"},
    {"STBStatus": "0", "RouterSNo": "R1", "STBLabel": "STB#8", "STBSno": "SN007"}
]
</code></pre>

<p>Javascript:</p>

<pre><code>&lt;script&gt;

 function stbststus(){
  show_alert()
    $.getJSON("Json", function(result){
        $("#STBStatus").empty();
          $.each(result, function(i, item){
            if(item.STBStatus == "1"){
              colorclass = "available"
            }
            if(item.STBStatus == "0"){
              colorclass = "offline"
            }
            if(item.STBStatus == "2"){
              colorclass = "In use"
            }
              $("#STBStatus").append("&lt;label class='radio'&gt;&lt;input type='radio' name='optradio'  class='optradio'&gt;"+item.STBLabel +"   &lt;i class='fa fa-circle pull-right  "+colorclass+"' aria-hidden='true'&gt;&lt;/i&gt;&lt;/label&gt; &lt;hr&gt;");
          });
      });
 }
&lt;/script&gt;
</code></pre>

<p>layout.html</p>

<pre><code>  &lt;div class="quote-text scroller" id="STBStatus"&gt; &lt;/div&gt; 

&lt;div class="wrapper"&gt;
 &lt;div class="buttonHolder" onclick="pageload()"&gt;
&lt;p&gt;&lt;a href="Set_Top_Box" class="btn btn-primary btn-large"&gt;Get Settopbox Status &amp;raquo;&lt;/a&gt;&lt;/p&gt; 
</code></pre>

<p>Django will not handle onClick events or anything of sort, you are better off with javascript and or jquery for that.</p>

<p><strong>Jquery</strong></p>

<pre><code>$(function(){
  $('input[type="radio"]').click(function(){
    if ($(this).is(':checked'))
    {
      alert($(this).val());
    }
  });
});
</code></pre>

<p>or for vanilla JavaScript check this url <a href="http://www.dyn-web.com/tutorials/forms/radio/get-selected.php" rel="nofollow">Get Value of Selected Radio Button</a>.</p>

php python html django