Creating A Simple Date of Birth Dropdown Menu Using PHP/HTML

In this tutorial, we'll create a simple date of birth dropdown menu. The PHP for loop handles the loop-related statement (Initialize, Conditional, Increment or Decrement) For Month: Syntax The following syntax display the select element for month
  1. <select name = "month">
  2. <option>Month</option>
  3. <?php
  4. for($month = 1; $month <= 12; $month++)
  5. echo"<option value = '".$month."'>".$month."</option>";
  6. ?>
  7. </select>
Output loops
For Day: Syntax The following syntax display the select element for day
  1. <select name = "day">
  2. <option>Day</option>
  3. <?php
  4. for($day = 1; $day <= 31; $day++){
  5. echo "<option value = '".$day."'>".$day."</option>";
  6. }
  7. ?>
  8. </select>
Output loops
For Year: Syntax The following syntax display the select element for year
  1. <select name = "year">
  2. <option>Year</option>
  3. <?php
  4. $y = date("Y", strtotime("+8 HOURS"));
  5. for($year = 1950; $y >= $year; $y--){
  6. echo "<option value = '".$y."'>".$y."</option>";
  7. }
  8. ?>
  9. </select>
Output loops I hope that this tutorial help you to your project and future projects. Enjoy Coding!!!

Tags

Comments

Submitted byWindel Broce (not verified)on Fri, 06/18/2021 - 10:52

Good

Add new comment