2

Currently, if I have <input type="url">, someone adding a URL without the protocol will cause a message to appear, saying "Please enter a URL". Is it possible to assume http://, unless otherwise specified? If that requires the use of Javascript, or something overly complicated, is there a way to keep the url type on the input, without it stopping someone from completing the form?

user3331834
  • 41
  • 1
  • 6
  • 1
    Check this link: http://stackoverflow.com/questions/17946960/with-html5-url-input-validation-assume-url-starts-with-http – Rami Feb 20 '14 at 08:50
  • So my choices are to use a script, which is out of the question for me, or to use an attribute that won't have the same effects across all browsers? I think I'll just turn the url field into a normal text field, then. – user3331834 Feb 20 '14 at 08:53

1 Answers1

2

The implementation of <input type="url"> varies by browser. It can be implemented as a gadget that implies http:// at the start when no protocol part is present, or in some other way.

You can use the attribute value="http://" to specify an initial value, probably helping the user to get the URL syntactically right. But this is suitable for required fields only. Since http:// is not a valid URL (just a prefix), constraint validation will report an error, if the user does not change the initial value – which is fine for a required field, but not for an optional field.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390