Last Updated: December 26, 2018
·
4.589K
· dubrod

HTML5 Data Toggle Buttons [FORM]

HTML

<div data-toggle="buttons-radio">
<button type="button" class="btn" id="yesBtn" data-info='{"post":"1"}'>Yes</button><button type="button" class="btn" id="noBtn" data-info='{"post":"0"}'>No</button>
</div>

HIDDEN FIELD

<input type="hidden" id="post_to_fb" name="post_to_fb" value="">

jQuery

$('#yesBtn').click(function(e) {
e.preventDefault();
thisdata = $('#yesBtn').data('info').post;
//console.log(thisdata);
$("#post_to_fb").val(thisdata);
});

$('#noBtn').click(function(e) {
e.preventDefault();
thisdata = $('#noBtn').data('info').post;
//console.log(thisdata);
$("#post_to_fb").val(thisdata);
 });