简体   繁体   中英

get text area validated

f

this is an external javascript , but he name and email works correctly but it skips over the message box and goes to info submitted even if the text area is empty. I've tried multiple ways and I tried to different functions and calling both and it didn't work correctly i do want to keep the if statements because I honestly don't know another way that doesn't mess with my other code..

You got a whitespace in your textarea after the opening tag (the underscore represents the whitespace)

<textarea>_
</textarea>

You get a whitespace, because between the open and closing tag you define the text that is in the textarea by default.

However, you should trim the textarea content to remove any whitespace characters anyway. You should consider this for the other fields, with sting input, as well.

JS code is correct, I think the problem is the definition of Textarea. I fixed it and it works properly.

<textarea cols="40" rows="6" name="message" id="message"></textarea>

See https://jsfiddle.net/gwqq0x3a/ for complete example.

Textarea elements are defined like so:

<textarea cols="40" rows="6" name="message" id="message"></textarea

No need for that input stuff, textarea is already an input, and has the name and ID declared like so, that input type = "text" shouldn't be there :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM