Hello

Im looking for a good date picker and easy to implement. HTML, PHP, and/or Javascript.

Since this is professional, I need also several things:

1: Language support.
2: If I pick Feburary, it doesnt show a legal day as 31
3: 3 dropdown boxes: One for month, another for day and another for year
4: It needs to return a string such as 12-31-2012 which I can easy capture and send it via POST/GET. If can be configured even better
5: Lightweight; No external libraries

I perfer PHP, then HTML and last Javascript. God I hate Javascript.

Thank you

Dani AI

Generated

Short answer: build three server-rendered selects for month/day/year (localized labels), use a tiny bit of vanilla JavaScript to keep the Day select correct when Month/Year change, and always validate on the server before accepting the date. This satisfies 's requirement for three comboboxes, language support, no external libraries, and an output like 12-31-2012. It also follows ' reminder to prefer server-side validation.

Example client-side helper (vanilla JS) to recompute days in a month and preserve the selected day:

function daysInMonth(month, year) {
  // month: 1-12
  return new Date(year, month, 0).getDate();
}

function populateDays(daySelect, monthSelect, yearSelect) {
  var m = parseInt(monthSelect.value, 10);
  var y = parseInt(yearSelect.value, 10);
  var max = daysInMonth(m, y);
  var cur = Math.min(parseInt(daySelect.value || 1, 10), max);

  daySelect.innerHTML = '';
  for (var d = 1; d <= max; d++) {
    var opt = document.createElement('option');
    opt.value = d;
    opt.textContent = (d < 10 ? '0' + d : d);
    if (d === cur) opt.selected = true;
    daySelect.appendChild(opt);
  }
}

Server-side: accept the three fields, validate, then format for POST/GET. Using PHP's built-in date checks is simplest and reliable:

$day = (int)($_POST['day'] ?? 0);
$month = (int)($_POST['month'] ?? 0);
$year = (int)($_POST['year'] ?? 0);

if (!checkdate($month, $day, $year)) {
  // handle invalid date
}

$formatted = sprintf('%02d-%02d-%04d', $month, $day, $year); // "MM-DD-YYYY"

Notes and tips:

  • For localization render month names server-side (use setlocale or the Intl APIs) so labels match user language.
  • If you truly want zero JS, re-render on server when month/year change, but that causes round-trips.
  • Never trust only client-side checks — always validate on submit.
  • When populating year range, choose sensible bounds (e.g., current year ± X) to avoid huge select lists.

Recommended Answers

All 5 Replies

God I hate Javascript

Too bad... all of my users prefer the jQuery UI datepicker A LOT over three comboboxes. Consider your clients, not your preference. PHP only may be a little tricky. I am sure you'd want the days for February to adjust correctly without refreshing the page.

Too bad... all of my users prefer the jQuery UI datepicker A LOT over three comboboxes. Consider your clients, not your preference. PHP only may be a little tricky. I am sure you'd want the days for February to adjust correctly without refreshing the page.

Thank you for your opinion but no; 3 comboboxes will be what the audience of my page chooses.

If you use the default PHP date functions then you should be able to get it going. You can use setlocale to get other languages.

                                          If you use the default PHP date functions then you should be able to get it going. You can use setlocale to get other languages.

Problem is that it wont check for Feburary 31th right?

You can use checkdate to see which days are valid.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.