On a webshop, I need to check if the user has checked this payment choice, and if he checked the CGU rules.
So this my html :
<div id="choixPaiement">
<div class="choixDuReglement">
<ul>
<li><input type="radio" name="buttonModePaiement" value="tata"></li>
<li><input type="radio" name="buttonModePaiement" value="toto"></li>
<li><input type="radio" name="buttonModePaiement" value="titi"></li>
<li><input type="radio" name="buttonModePaiement" value="tutu"></li>
</ul>
</div>
<div id="accepte_cgv">
<p> <input type="checkbox" name="check_cgv" id="check_cgv"><label>Lu et approuvé</label></p>
<p><a onclick="validCommande();" class="btnValidCommande" href="javascript:;"><span>Valid my order</span></a></p>
</div>
</div>
And this is my javascript :
function validCommande(){
var paiement = $("input[@name=buttonModePaiement]:checked").val();
alert(paiement);
if(paiement == "undefined"){
alert('please choose payment method');
}
alert($('#check_cgv').is(':checked'));
}
when radiobutton and checkbox are not checked, I get two alert message : "undefined" and "false" (so that is correct).
But when I'm checking the checkbox, and no radiobutton, I get it : "on" and "true".
Why ?
undefined, you should usetypeof variable === 'undefined'.