Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textarea's "required" attribute doesn't work even though the value is empty

I created a simple page with list box and text area with conditions that all should be required.

List box are working fine, but textarea box doesn't tell that the field is required to be filled.

<!DOCTYPE html> <html> <head> <title>Ratings & Reviews</title> <body> <form>  <span>Customer Service*</span> <span>     <select name=customer id=aa required>         <option selected="rate" value="" disabled>rate</option>         <option value=1>1</option>         <option value=2>2</option>         <option value=3>3</option>         <option value=4>4</option>         <option value=5>5</option>     </select> </span> <br><br> <span>Value for money*</span> <span>     <select name=money id=aa required>         <option selected="rate" value="" disabled>rate</option>         <option value=1>1</option>         <option value=2>2</option>         <option value=3>3</option>         <option value=4>4</option>         <option value=5>5</option>     </select> </span>  <div>     <textarea name="reviews" rows=11 cols=50 maxlength=250 required>     </textarea> </div>  <div id=submit>     <br>     <input type=submit name=submit value=submit> </div>  </form> </body> </html> 
like image 650
divakar.scm Avatar asked Jun 12 '13 08:06

divakar.scm


People also ask

Why required attribute is not working?

If the input elements aren't inside a form tag then HTML5 required attribute will fail to work. So always put input tags inside a form along with the form encapsulation itself.

Can you make textarea required?

The required attribute is a boolean attribute. When present, it specifies that a text area is required/must be filled out (in order to submit the form).

Does textarea have value attribute?

<textarea> does not support the value attribute.

How do I get rid of extra space in textarea?

Just put your php open tag right after the textarea close tag.. Dont use line break.. And close php exactly before (as you have done).. This will erase all the whitespaces..


2 Answers

You have empty space inside text area, remove it:

 <textarea name="reviews" rows=11 cols=50 maxlength=250 required ></textarea> 

Fiddle demo

like image 171
sinisake Avatar answered Sep 24 '22 15:09

sinisake


The problem is with the spaces between the tags. You are not supposed to give any spaces in html between these tags, otherwise browser will consider it as the value.

like image 36
Siddharth Nagar Avatar answered Sep 24 '22 15:09

Siddharth Nagar