I have this code applied to a input test type onClick="this.value+='http://'", but I want to modify it so that it only adds http:// the first time the user clicks the input.
Any ideas? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer to your question is obvious (slightly modified, to prefix text with
http://):However, this method is error-prone, and ugly. You probably want to force a text to be prefixed with
http://. The code will not work if the user navigates to the input field using keys (such as tab).An improved approach would be:
Still, depending on your exact application, other methods are even more suitable.