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

              
                  <form>

    <select id="yearSelect">
      <!-- JavaScriptで生成される年のセレクトメニューがここに追加される -->
    </select>
    <label for="yearSelect">年</label>
    <select id="monthSelect">
      <!-- JavaScriptで生成される月のセレクトメニューがここに追加される -->
    </select>
    <label for="monthSelect">月</label>
    
    <select id="daySelect">
      <!-- JavaScriptで生成される日のセレクトメニューがここに追加される -->
    </select>
    <label for="daySelect">日</label>
  </form>
              
            
!

CSS

              
                form {
  display: flex;
  align-items: center;
}

select {
  padding: 6px 8px;
  font-size: 14px;
  margin-right: 6px;
}

label {
  margin-right: 6px;
}

body{
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  min-height:100vh;
}
              
            
!

JS

              
                /* 生年月日 */
// HTMLの年、月、日のセレクト要素のidを指定
var yearSelect = document.getElementById("yearSelect");
var monthSelect = document.getElementById("monthSelect");
var daySelect = document.getElementById("daySelect");

// 年の範囲を計算する
var currentYear = new Date().getFullYear();
var startYear = currentYear - 80;
var endYear = currentYear - 20;

// 年のセレクトメニューを生成
var defaultOptionYear = document.createElement("option");
defaultOptionYear.value = "";
defaultOptionYear.text = "- 選択 -";
defaultOptionYear.selected = true;
defaultOptionYear.disabled = true;
yearSelect.appendChild(defaultOptionYear);

for (var year = startYear; year <= endYear; year++) {
  var optionElement = document.createElement("option");
  optionElement.value = year;
  optionElement.text = year;
  yearSelect.appendChild(optionElement);
}

// 月のセレクトメニューを生成
var defaultOptionMonth = document.createElement("option");
defaultOptionMonth.value = "";
defaultOptionMonth.text = "- 選択 -";
defaultOptionMonth.selected = true;
defaultOptionMonth.disabled = true;
monthSelect.appendChild(defaultOptionMonth);

for (var month = 1; month <= 12; month++) {
  var optionElement = document.createElement("option");
  optionElement.value = month;
  optionElement.text = month;
  monthSelect.appendChild(optionElement);
}

// 日のセレクトメニューを生成
var defaultOptionDay = document.createElement("option");
defaultOptionDay.value = "";
defaultOptionDay.text = "- 選択 -";
defaultOptionDay.selected = true;
defaultOptionDay.disabled = true;
daySelect.appendChild(defaultOptionDay);

function updateDays() {
  var selectedMonth = monthSelect.value;
  var selectedYear = yearSelect.value;

  // 選択された月に応じて日数を計算
  var daysInMonth = new Date(selectedYear, selectedMonth, 0).getDate();

  // 日のセレクトメニューをリセット
  daySelect.innerHTML = '';
  
  daySelect.appendChild(defaultOptionDay);

  // 日のセレクトメニューを生成
  for (var day = 1; day <= daysInMonth; day++) {
    var optionElement = document.createElement("option");
    optionElement.value = day;
    optionElement.text = day;
    daySelect.appendChild(optionElement);
  }
}

// 月が変更されたら日のセレクトメニューを更新
monthSelect.addEventListener("change", updateDays);

// 年が変更されたら日のセレクトメニューを更新
yearSelect.addEventListener("change", updateDays);

// 初期状態で日のセレクトメニューを更新
updateDays();
              
            
!
999px

Console