Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- </head>
- <body>
- <label for="opt1"><input class="radio-button-selector" type="radio" name="account" id="opt1" value="opt1">Opt1</label>
- <label for="opt2"><input class="radio-button-selector" type="radio" name="account" id="opt2" value="opt2">Opt2</label>
- <div id="form_select" class="form-group">
- <select id="term" name="term" class="form-control">
- <option value="0">Please select</option>
- <option value="6">6 months</option>
- <option value="9">9 months</option>
- <option value="10">10 months</option>
- <option value="12">12 months</option>
- <option value="18">18 months</option>
- <option value="24">24 months</option>
- <option value="30">30 months</option>
- <option value="36">36 months</option>
- <option value="42">42 months</option>
- <option value="48">48 months</option>
- </select>
- </div>
- <script type="text/javascript">
- if (window.jQuery) {
- // jQuery is available.
- }
- else { console.log("-- no jquery --"); }
- </script>
- <script type="text/javascript">
- $(document).ready(function() {
- $("input.radio-button-selector").change(function(){
- console.log("Changed.");
- if ( $(this).val() == "opt2" ) {
- $("#term option[value='48']").hide();
- $("#term option[value='42']").hide();
- }
- else if ( $(this).val() == "opt1" ) {
- $("#term option[value='48']").show();
- $("#term option[value='42']").show();
- }
- });
- });
- </script>
- </body>
- </html>
- $(document).ready(function() {
- var monthsDifference = $("#term option[value='48'], #term option[value='42']");
- $("input.radio-button-selector").change(function(){
- if ( $(this).val() == "opt2" ) {
- monthsDifference.hide();
- }
- else if ( $(this).val() == "opt1" ) {
- monthsDifference.show();
- }
- });
- });
- $(document).ready(function() {
- var optionMonths = {
- opt1: [6,9,10,12,18,24,30,36,42,48],
- opt2: [6,9,10,12,18,24,30,36]
- }
- //Cache all options
- var $options = $("#term option");
- $("input.radio-button-selector").change(function(){
- //Hide all options first
- $options.hide();
- //Then show relevant options
- showOptionMonths( optionMonths[ $(this).val()] );
- });
- });
- function showOptionMonths( months ){
- months.forEach( function( month ){
- $("#term option[value='" + month + "']").show();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement