I'm trying to execute a jQuery script to change the data-url attribute based on which radio button is clicked/selected.
But my code won't work when I put it inside the if statement to check which radio button is active. It will successfully replace the data-url attribute though when executing without an if statement.
<div id="samcart" class='samcart-popup-container' style='margin:auto;width:200px;align:center;' data-id='123' data-url='empty'>
<div class='samcart-popup-button' type='button' class='btn btn-default css3button'>
Join
</div>
Here's the Jquery script
$('input[name="radio1"]').on('change', function(){
if ($(this).val()=='yearly') {
var a = $('#samcart').data('url');
$('#samcart').attr("data-url","www.urlhere.com");
} else if ($(this).val()=='quarterly') {
var a = $('#samcart').data('url'); $('#samcart').attr("data-url","www.url2here.com");
} else{
var a = $('#samcart').data('url'); $('#samcart').attr("data-url","www.url3here.com");
} });
Aucun commentaire:
Enregistrer un commentaire