How can I check whether a browser supports the HTML5 form attribute on input elements?
Following this question, I've tried the following:
var supportForm = function()
{
  var input = document.createElement("input");
  if ("form" in input)
  {
    input.setAttribute("form", "12345");
    if (input.form == "12345")
      return true;
  }
  return false;
}
... but that gives a false negative for FireFox (14, at least). Replacing input.form with input.getAttribute("form") gives a false positive for IE 9.
The type attribute specifies the type of <input> element to display. If the type attribute is not specified, the default type is "text".
range: This input type allows the user to enter a numerical value within a specified range. search: This input type allows the user to enter a search string within the input field. tel: This input type allows the user to enter a telephone number. url: This input type allows the user to enter the URL.
For input elements there was a reference to the parent form before the HTML5 form reference feature and this causes this problem you mention.
I hope there is a more elegant way to check if it is supported but for now you could use the following (but it involves dealings with the DOM):
function testInputFormSupport() {
    var input = document.createElement('input'),
         form = document.createElement('form'),
         formId = 'test-input-form-reference-support';
    // Id of the remote form
    form.id = formId;
    // Add form and input to DOM
    document.childNodes[0].appendChild(form);
    document.childNodes[0].appendChild(input);
    // Add reference of form to input
    input.setAttribute('form', formId);
    // Check if reference exists
    var res = !(input.form == null);
    // Remove elements
    document.childNodes[0].removeChild(form);
    document.childNodes[0].removeChild(input);
    return res;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With