Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Modal Quiz with Radio button"
Bootstrap 3.2.0 Snippet by
sravansurepally
3.2.0
modal
radio
Preview
HTML
CSS
JS
View Full Screen
Forked from
Fork
Fork this
Parent
1.7K
 
0 Fav
Post to Facebook
Tweet this
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div id="myModal" class="modal fade in" tabindex="-1" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h3>Take a Quiz!</h3> </div> <div class="modal-body"> <div class="quiz" data-toggle="buttons"> <label class="btn btn-labeled btn-default btn-block"> <span class="btn-label"><i class="glyphicon"></i></span><input type="radio" name="q" value="1">answer one </label> <label class="btn btn-labeled btn-default btn-block"> <span class="btn-label"><i class="glyphicon"></i></span><input type="radio" name="q" value="2">answer two </label> <label class="btn btn-labeled btn-default btn-block"> <span class="btn-label"><i class="glyphicon"></i></span><input type="radio" name="q" value="3">answer three </label> </div> </div> <div class="modal-footer"> <span id="answer"></span> <!-- hide close button, hide when correct choice only! --> </div> </div> </div> </div>
/* CSS label from http://bootsnipp.com/snippets/featured/buttons-with-labels */ .btn-label {position: relative;left: -12px;display: inline-block;padding: 6px 12px;background: rgba(0,0,0,0.15);border-radius: 3px 0 0 3px;} .btn-labeled {padding-top: 0;padding-bottom: 0;} .btn { margin-bottom:10px; } .btn-block {text-align:left;}
$(window).load(function(){ $('#myModal').modal({ backdrop: 'static', keyboard: false }); }); $("label.btn").on('click',function () { $(this).parent('div.quiz').find('i').removeClass('glyphicon-remove'); $(this).find('i').addClass('glyphicon-remove'); $(this).parent('div.quiz').find('.btn-success').addClass('btn-default').removeClass('btn-success'); $(this).addClass('btn-success'); var choice = $(this).find('input:radio').val(); $( "#answer" ).html( $(this).checking(choice)+ " is checked!" ); }); $ans = 3; $.fn.checking = function(ck) { if (ck != $ans) return 'INCORRECT'; else return 'CORRENT'; };
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76