I’m trying to validate a textarea making sure that each line starts with ‘http://’:
When the url is wrong, it executes the else statement but if it’s correct, it isn’t getting executed.
What’s the problem?
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.
It doesn’t work because
thisrefers to a String object. theafterfunction expects a jQuery object or a string. Strangely enough, in javascript strings are different from String objects. Your else statement works becausethisis being converted into a string behind the scenes when you concat a regular string to it. However, the if fails becausethisremains a String object in this case. You can fix it in a couple of ways, but here is one of them:EDIT
here’s a link to another SO question that discusses this in more detail Why are there two kinds of JavaScript strings?