javascript - How I change a value of hidden file in the file HTML.Twig -
this question has answer here:
i have in file html.twig
:
1: one
hidden filed should take 3 values according radio selected, 1 database , 2 others value 10.
<input type="hidden" name="lt_filed" value="{{ price.getlt }}" or "10" or "10">
2: 3 radio box
<input id="spa-price" name="price" class="w3-radio" onchange='valuelt();' value="spare {{ price.getspareprice }}" type="radio"> <input id="rep-price" name="price" class="w3-radio" onchange='valuelt();' value="repair{{ price.getrepairprice }}" type="radio"> <input id="tes-price" name="price" class="w3-radio" onchange='valuelt();' value="test {{ price.gettestprice }}" type="radio">
3: did block javascript in same file html.twig, created function values of each radio, following:
{% block javasc %} <script> function valuelt(){ var spare= document.getelementbyid('spa-price'); var repair= document.getelementbyid('rep-price'); var test= document.getelementbyid('tes-price'); var hidden_filed = document.getelementsbyname("lt_filed"); if (repair.checked){ // should take value 10 alert("repair checked"); hidden_filed.value = 10; } else if (test.checked){ // should take value 10 alert("test checked"); hidden_filed.value = 10; } else { alert("spare checked"); // should take value database hidden_filed.value = {{ price.getlt }};// here can't recovred value database } } </script> {% endblock %}
can tell me how can value {{ price.getlt }}
twig or javascript ?
thank you.
well, document.getelementsbyname(param)
function doesn't return element instance, returns array of elements. should pick first element :
{% block javasc %} <script> function valuelt(){ var spare= document.getelementbyid('spa-price'); var repair= document.getelementbyid('rep-price'); var test= document.getelementbyid('tes-price'); var hidden_filed = document.getelementsbyname("lt_filed")[0]; // change line if (repair.checked){ // should take value 10 alert("repair checked"); hidden_filed.value = 10; } else if (test.checked){ // should take value 10 alert("test checked"); hidden_filed.value = 10; } else { alert("spare checked"); // should take value database hidden_filed.value = {{ price.getlt }};// here can't recovred value database } } </script> {% endblock %}
Comments
Post a Comment