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.
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.
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?
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!
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.
This topic is now closed. New replies are no longer allowed.