0

I have an order form with different delivery methods. I would like if we select shipments by Belgian post that the var Delivery is equal to 2 that when we choose mondial relay belgique that the var Delivery is equal to 3 that when we choose France post that the delivery var is equal to 4. that when we choose mondial relay france that the delivery var is equal to 5. I tried the code below but it does not work

<div>
<input type="radio" id="mondial_relay_belgique" name="envois" value="2"  >
<label for="mondial_relay_belgique">Envois par mondial relay belgique 5 euros</label>
</div>
<div>
<input type="radio" id="poste_belgique" name="envois" value="3" >
<label for="poste_belgique">envois par poste belgique 4 euros</label>
</div>
<div>
<input type="radio" id="mondial_relay_france" name="envois" value="4" checked="checked" >
<label for="mondial_relay_france">Envois par mondial relay france 3 euros</label>
</div>
<div>
<input type="radio" id="poste_france" name="envois" value="5" >
<label for="poste_france">envois par poste france 2 euros</label>
</div>
if (document.getElementById('poste_belgique').checked) {
var Livraison=2;
}
if(document.getElementById("mondial_relay_belgique").checked) {
var Livraison=3;
}
else if(document.getElementById('poste_france').checked) {
 var Livraison=4;
}
else if(document.getElementById('mondial_relay_france').checked) {
var Livraison=5;
}
flexi2202
  • 11
  • 5
  • 2
    Does this answer your question? [How to get value of selected radio button?](https://stackoverflow.com/questions/15839169/how-to-get-value-of-selected-radio-button) – Visne Jan 06 '22 at 07:24
  • [What Do You Mean “It Doesn’t Work”?](//meta.stackexchange.com/q/147616/289905) `const Livraison = Number(document.querySelector("input[type='radio'][name='envois']:checked").value);`. You don’t need the IDs for this. Remove them. – Sebastian Simon Jan 06 '22 at 07:27
  • A big thank you for the answer. I get 0 whatever the button chosen. Your code I must use it as is? – flexi2202 Jan 06 '22 at 07:51
  • I just tried the code but each time I get 0 regardless of the button chosen – flexi2202 Jan 06 '22 at 07:55

0 Answers0