zaggs — 2012-05-10T05:43:50-04:00 — #1
What I need to do is force the value "http://" to the beginning of a text input. It shouldn't allow the user to delete it.
Does anyone know how to do this?
Thanks in advance.
paul_wilkins — 2012-05-10T07:39:18-04:00 — #2
A solution is to not put http:// in the text input.
<label>Path: http://<input name="path"></label>
That way the user gets to visibly see that http:// is already there, and the server when it receives the submitted data can deal with the path as it sees fit. The server can then add http:// to the path.
zaggs — 2012-05-10T10:14:35-04:00 — #3
Thanks for your reply. I already was using this method but unfortunately we cannot depend on the user seeing the "http://". We are getting lots of people still entering http:// and some just entering the domain name (i.e. google.com).
What I wanted was to pre-populate the text field with "http://" and not let that value be deleted. Is this possible?
logic_earth — 2012-05-10T10:28:01-04:00 — #4
That is why you validate and filter input before you work with it. If you need a URL with HTTP:// attached then you make sure it is properly formatted when you work with it. You should already be doing this!
paul_wilkins — 2012-05-10T16:16:14-04:00 — #5
Not really, no. The problems come in when dealing with the user typing, or pasting an existing URL, because whenever the user edits the value, that changes the position of the insertion bar, and such issues don't tend have cross-browser friendly solutions.
Validation of user input is a much easier and more effective solution.
If you want to reinforce to the user what you want the field to start, you can set the default value of the field to http:// to help clue them in to your wishes.
If after entering their value it doesn't meet up with your requirements, that is where standard validation occurs to resolve such issues.