php - How do I tell which radio button was selected in file HTML-Twig -


i have 4 radio buttons in code html:

<input id="spa-price" name="price" class="w3-radio" value="spare {{ price.getspareprice }}" type="radio"> <input id="spa-price" name="price" class="w3-radio" value="repair {{ price.getrepairprice }}" type="radio"> <input id="spa-price" name="price" class="w3-radio" value="test {{ price.gettestprice }}" type="radio"> <input id="spa-price" name="price" class="w3-radio" value="std-exchange {{ price.getexchangeprice }}" type="radio"> 

on post, want output hidden field value of selected radio button, eg:

<input type="hidden" name="lt" value="{{ price.getlt }}"> 

the code have @ moment:

{% if $_post['price'] == 'spare' %} <input type="hidden" name="lt" value="{{ price.getlt }}">  {% elseif $_post['price'] == 'repair' %}  <input type="hidden" name="lt" value="{{ 10 }}">  {% elseif $_post['price'] == 'test' %}  <input type="hidden" name="lt" value="{{ 10 }}">  {% else $_post['price'] == 'exchange' %}  <input type="hidden" name="lt" value="{{ price.getlt }}"> 

currently, not work.

what error ? thank you.

first, have given every checkbox made same id bad practice. in html every id should have unique name. suggest same names. optional

so change id's this:

<input id="spare-price" name="price" class="w3-radio" value="spare {{ price.getspareprice }}" type="radio"> <input id="repair-price" name="price" class="w3-radio" value="repair {{ price.getrepairprice }}" type="radio"> <input id="test-price" name="price" class="w3-radio" value="test {{ price.gettestprice }}" type="radio"> <input id="exchange-price" name="price" class="w3-radio" value="std-exchange {{ price.getexchangeprice }}" type="radio"> 

you can use javascript check if box checked

{% block javascripts%}   <script>         function validate(){           var spare= document.getelementbyid('spare-price');           if (spare.checked){             alert("checked") ;           }else{             alert("you didn't check spare-price! let me check you.")           }         }      </script>     {% endblock %} 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -