Jump to content

Recommended Posts

How to Limit number of character in each line in textarea Let say script should allow maximum 4 rows and should allow 8 character in each line. Also If character reached the limit then it should move to next line.

 

its will look like this:

 

12345678

90123456

78901234

 

 

this is my code what i need to add

<textarea name="text" cols="76" rows="15" lang="lt"></textarea>

I will give you example there is a textdraw with 4 rows.

after you type 8 characters at the first row it's automatic go to the next row (row 2)

after you type 8 characters at the second row it's automatic go to the next row (row 3)

 

 

and.. more..

You can limit the number of cols to 8, otherwise you'll need some JS.

 

<textarea rows="4" cols="8">

 

That only affects the visual appearance, it has no control over the limit of characters.

 

--

 

As explained in your other thread about this, it will need to be done using JS. You'll also notice there's not a lot of help about this as it's not going to be easy to achieve. Validating the entry shouldn't be difficult (split() the string by "\n" and check the length() of the array and length() of each value), but it's placing the cursor on the next line when it reaches the 8th character will be tricky. JS has little standards when it comes to cursor objects, so making it all cross-browser will be a challenge too.

 

Have you considered an alternative? What about a series of 4 text inputs with the maxlength attribute set to 8 on each, and the name set as an array (i.e. <input type="text" name="text[]" (...)). Then on the keyup event for each, check the length of the input; if it's 8 characters long set focus to the next input. In the handling PHP if you need the text as a single string, you can just implode the array with "\n" as the delimiter.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.