What is the "dirname" attribute in HTML for?

Asked

Viewed 159 times

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 had never seen (until today) this attribute dirname in no tutorial, nor being used in practice.

I wonder what it’s for.

2 answers

9


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

Makes sense if used in conjunction with the style direction and in languages such as Arabic.

Take the example:

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

If you submit the field, the query string will receive:

"?search=texto&research"

indicating that the search value was typed "rtl" that is, from right to left. If typed from left to right would post "search"

Here is a site explaining and where it is possible to test Submit: https://www.wufoo.com/html5/dirname-attribute/

5

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

The values that 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 Arabic.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.