What is the "dirname" attribute in HTML?

8

I saw on the internet a code similar to this:

<form action="/the-action">
  First name: <input type="text" name="fname" dirname="fname.dir">
  <input type="submit" value="Submit">
</form>

I've never seen (this day) this dirname attribute in any tutorial, nor being used in practice.

I'd like to know what it's for.

    
asked by anonymous 10.07.2018 / 18:28

2 answers

9

This attribute posts information if the text was typed from left to right (default for nodes) or from right to left, and used to receive the value entered and know how it was typed.

It makes sense if used in conjunction with the direction style and in languages like Arabic.

See the example:

<span>Texto para pesquisar:</span>
<input type="text" name="pesquisa" style="direction:RTL" dirname="pesquisaDirecao" />

If the field is submitted, the query string will receive:

  

"? search = text & searchDirection = rtl"

indicating that the search value was typed "rtl" ie from right to left. If typed from left to right it would post "searchDirection = ltr"

Here's a site explaining and where you can test submit: link

    
10.07.2018 / 18:50
4

According to W3Schools , the dirname attribute of a input enables the text direction of an input is sent to the server.

The values the server should receive in this case should be ltr if the text is written from left to right, or rtl , if the text is written from right to left.

One of the cases where right-to-left writing is used is in the Arabic language.

    
10.07.2018 / 18:39