Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                main.content
  .content__select
    label(for="select01") 質問1
    select#select01.js-selectSample.js-check
      option(value='') 選択してください
      option(value='1-1') 選択肢1-1
      option(value='1-2') 選択肢1-2
    p.js-error__required.is-hide 質問1を選択してください
  .content__select
    label(for="select02") 質問2
    select#select02.js-selectSample.js-check
      option(value='') 選択してください
      option(value='2-1') 選択肢2-1
      option(value='2-2') 選択肢2-2
      option(value='2-3') 選択肢2-3
    p.js-error__required.is-hide 質問2を選択してください
  div
    a#link.js-submit.is-disabled(href='https://example.com/') 結果を見る
  p.content__hint ↑↑リンク:
    span#linkText https://example.com/
    
              
            
!

CSS

              
                .js-error__required {
  line-height: 1;
  color: red;
  font-size: 10px;
  margin-top: 5px;
}
.is-hide {
  display: none;
}
.is-disabled {
  opacity: 0.7;
  pointer-events: none;
}

// only for layout
.content {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
}

.content__select {
  margin: 15px 0;
}

.content__hint {
  font-size: 14px;
  margin-top: 15px;
}
              
            
!

JS

              
                $(function() {
  const formSelect = $('.js-selectSample');
  const link = $('#link');
  const linkText = $('#linkText'); // codepen用
  formSelect.on('change', function() {
    // formSelectを配列で取得し、&で繋ぐ
    const valueArray = formSelect.map(function() {
      return `${$(this).val()}`;
    }).get().join('&');
    // 選択肢によって新しいurlを発行する
    const hrefTop = "https://example.com/";
    const lower01 = "lower-1";
    const lower02 = "lower-2";
    const lower03 = "lower-3";
    const lower04 = "lower-4";
    const lower05 = "lower-5";
    const lower06 = "lower-6";
    if(valueArray == "1-1&2-1") {
      link.attr({href: hrefTop + lower01});
      linkText.html(hrefTop + lower01); // codepen用
    } else if (valueArray == "1-1&2-2"){
      link.attr({href: hrefTop + lower02});
      linkText.html(hrefTop + lower02); // codepen用
    } else if (valueArray == "1-1&2-3") {
      link.attr({href: hrefTop + lower03});
      linkText.html(hrefTop + lower03); // codepen用
    } else if (valueArray == "1-2&2-1") {
      link.attr({href: hrefTop + lower04});
      linkText.html(hrefTop + lower04); // codepen用
    } else if (valueArray == "1-2&2-2") {
      link.attr({href: hrefTop + lower05});
      linkText.html(hrefTop + lower05); // codepen用
    } else if (valueArray == "1-2&2-3") {
      link.attr({href: hrefTop + lower06});
      linkText.html(hrefTop + lower06); // codepen用
    } else {
      link.attr({href: hrefTop});
      linkText.html(hrefTop); // codepen用
    }
  });
});

// バリデーション
$('.js-check').on('change', function () {
  let value = $(this).val();
  if (value.length === 0) {
    $(this).addClass('js-error');
    $(this).siblings(".js-error__required").removeClass('is-hide');
  } else {
    $(this).removeClass('js-error');
    $(this).siblings(".js-error__required").addClass('is-hide');
  }
  checkAll();
});

function checkAll() {
  let valid = true;
  const checkEls = $('.js-check');

  for (let i = 0; i < checkEls.length; i++) {
    const val = $(checkEls[i]).val();
    valid &= (!!val && val !== '');
  }

  if (valid) {
    $('.js-submit').removeClass('is-disabled');
  } else {
    $('.js-submit').addClass('is-disabled');
  }
}
              
            
!
999px

Console