How to check HTML version?

I created a website and one input is for date using <input type="date" name="rcdate" />. It is very handy but it only works for Chrome. The output when I process it using PHP is YYYY-MM-DD format.

The problem is when someone uses an outdated browser (Note: Firefox, IE), the UI is not working (Note: displays a textbox) and the user is prompted to input the date him/herself and the format is always inconsistent and MySQL format for the date is YYYY-MM-DD.

Can anyone provide an HTML version checker so that the user will have a message that his/her browser is not compatible with my site? Thanks. Any other suggestions on how to bypass this is welcome as well.

EDIT: My code for processing date are as follows:

<?php
if(isset($_POST['rcdate'])){ $rcdate= $_POST['rcdate']; }
$strSQL = "Insert INTO nqascorecard (
    `RcDate`
    VALUES (
    '$rcdate'
    )";
$rs = mysql_query($strSQL) or die(mysql_error());
?>

Upvotes: 1

Views: 6076

Answers (3)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201866

There is no way to “check HTML version” in general, but you can use feature checks with Modernizr or directly in your JavaScript code. That is, you can e.g. check whether the browser recognizes the type=date attribute (so that it is reflected in the DOM). However, the issue here is really: what should you do if the feature (like input type=date) is not supported? If you have a good backup plan, like using a JavaScript widget, why not simply use it instead of input type=date? Moreover, it is possible that the feature check does not really work: a browser might recognize type=date but fail to provide a reasonable UI that implements it.

When support to input type=date has become widespread and when (or if) has been properly localized (current HTML5 drafts are messy about this, and implementations tend to localize by system locale, not page locale), you can use input type=date with simple backup: if the browser does not support it (so that it falls back to a simple text input box), insert instructions that tell the user to use the yyyy-mm-dd format. Or, to be on the safer side, put those instructions into the static content and remove them with JavaScript if you can detect that the browser has real support to input type=date.

Upvotes: 2

adear11
adear11

Reputation: 945

It would be much better to use something like Modernizr to detect if the date type is supported and implement a javascript fall back for a date picker if it doesn't. Not many desktop browsers support the date input method. See http://caniuse.com/#feat=input-datetime

Upvotes: 3

Andy Haskell
Andy Haskell

Reputation: 717

The HTML5 "date" input type is not currently supported by Firefox and Internet Explorer according to w3schools http://www.w3schools.com/html/html5_form_input_types.asp

However, there are JavaScript-based calendars like this one form jQuery UI http://jqueryui.com/datepicker/ that are built to be cross-browser compatible, so I would recommend using something like that so you don't have to do browser-sniffing.

Upvotes: 1

Related Questions