Html textarea with lines

How to add line-breaks to a textarea with text over more lines

The following approach takes input text from HTML Textarea and adds line breaks using JavaScript. In the following code, the input from the textarea is processed by JavaScript on the click of the submit button to produce a required output with line breaks.

How to add line-breaks to a textarea with text over more lines

I am using a textarea width about 300px with, 2 rows and a maxlength.

If the text is two rows long I do not receive any line breaks (
or \n ) in the $_POST var.

string(35) "test test test test test test test " 

I want to achieve this output depending on where the natural breakpoint into the second row is:

string(35) "test test test test test\n test test " 

Any ideas if thats possible?

You can add the attribue wrap=»hard» and it will send a newline wherever it wraps:

Читайте также:  Python for android linux

You can approximate it if you use the wordwrap function

or, if you need HTML breaks

PS Make sure you’re sanitizing the input before hand so you’re not vulnerable to XSS and other attacks.

Preserve line break in textarea when using mailto, var myLineBreak = message2.replace(/\r\n|\r|\n/g, «%0D%0A»);. Now it works perfectly.

Html/css — Input text area, move to/break new line once width is reached

I am building a chat UI and I have figured out how to break the message text when the width is reached using word-break: break-all in my css script for received and sent messages. I can not figure how to do it to my actual input field where the user writes the text. It all goes in one line while typing instead of breaking like it would sending a text message on a smart phone.

I have tried adding word-break: break-all into my &__textbox method but it doesn’t seem to be working and I am not sure why. Can someone point out why it’s not working? I have found examples of another UI doing it but I can’t seem to find what is allowing linebreaks in the input field.

* < box-sizing: border-box; >body < margin: 0; height: 100%; font-family: arial; font-size: 62.5%; >.chatbox-avatar < width: 80px; height: 80px; overflow: hidden; border-radius: 50%; background: white; padding: 3px; box-shadow: 0 0 5px 0 rgba(0, 0, 0, .2); position: absolute; transition: .1s ease-out; bottom: 0; left: 1px; >.chatbox-avatar img < width: 100%; height: 100%; border-radius: 50%; >.c-chat-window < height: 300px; width: 250px; position: relative; border-top-left-radius: 5px; border-top-right-radius: 5px; font-size: 12px; &__messages < border: 1px solid lightgrey; border-top: 0; border-bottom: 0; height: calc(100% - 68px); overflow-y: scroll; padding: 0 10px; position:absolute; top: 34px; line-height: 1.4; width: 100%; >&__compose < position: absolute; bottom: 0; left: 0; right: 0; display: flex; border: none; >&__text-box < flex: 1; height: 40px; width: 100%; border:0; border-top: 1px solid lightgrey; border-left: 1px solid lightgrey; padding: 0 10px; >&__button < border: none; background: orangered; padding: 0 15px; color: white; >&__container < position: absolute; bottom: 0; right: 50px; word-break: break-all >&__header < background: blue; border-bottom: 1px solid white; color: white; cursor: pointer; padding: 10px; top: 0; left: 0; right: 0; position: absolute; border-top-left-radius: 5px; border-top-right-radius: 5px; z-index: 10; >.chat-partner-name < flex: 1; padding: 0 0 0 80px; font-size: 15px; color: white; >&__target < height: 40px; background: orangered; cursor: pointer; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; padding: 0 25px; >&__message < padding: 10px; border-radius: 10px; width: 80%; &--sent < background: orangered; color: white; margin-left: auto; word-break: break-all >&--received < background: lightgrey; margin-right: auto; word-break: break-all >> &__notification < background: dodgerblue; border-radius: 50%; height: 20px; width: 20px; position: absolute; z-index: 15; right: 0; top: -15px; display:flex; &::after < content: ''; display:inline-block; margin: auto; height:5px; width:5px; background-color: white; position: absolute; left: calc(50% - 2.5px); top: calc(50% - 2.5px); >> &--hide < display: none; >> 
 
Chatbot

In order to have line breaks, you should use the element.

Line-break — CSS: Cascading Style Sheets, The line-break CSS property sets how to break lines of Chinese, Japanese, or Korean (CJK) text when working with punctuation and symbols.

Textarea breaks words and doesn’t make new lines

I have an issue with textarea of phpBB forum. When users type in some content in some cases the line doesn’t break, so the line continues without breaking to new line. In my case when I type content the words itself break for a new line.

for example, «machine» will be broken to «mach».. starting from the new line .. «ine» and I know that if there’s no enough space for a word it should be moved to the new line.

I tried almost everything that I searched on the internet. Could someone let me know how to override every property and set textarea to the default, proper settings?

#message-box textarea.inputbox < width: 100%; height: auto; resize: none; >#message-box textarea < color: #333333; >textarea.inputbox

Html — make textarea wrap mid-word, Can be useful when your textarea is not representing words but series of different kind of characters (containing numbers, letters, spaces,

How to add line breaks to an HTML textarea?

Way of implementing line breaks differ from one platform to another. The following approach takes input text from HTML Textarea and adds line breaks using JavaScript.

Approach:
This task can be achieved by using some predefined array and string functions provided by JavaScript. In the following code, the input from the textarea is processed by JavaScript on the click of the submit button to produce a required output with line breaks.

Functions Used:
split(): is a predefined JavaScript function that splits a string into an array using a parameter.
join(): is a predefined JavaScript function that joins an array to convert it into a string using provided parameters.

Источник

How to Create a Multi-Line Text Input Field In HTML

Next, see examples of adding a multi-line text area with a «submit» button.

Example of creating a multi-line input field:

html> html> head> title>Title of the document title> head> body> form action="/form/submit" method="GET"> textarea rows="5" cols="60" name="text" placeholder="Enter text"> textarea> br/> input type="submit" value="submit"/> form> body> html>

You can also create a label for the textarea using the tag:

html> html> head> title>Title of the document title> head> body> form action="/form/submit" method="post"> label for="text">Add Comments: label> br> textarea id="text" name="text" rows="12" cols="50"> textarea> br/> input type="submit" value="Submit"> form> body> html>

Источник

HTML Textarea with Line Numbers – jQuery Lined Textarea

Lined Textarea is a lightweight (4 KB only), cross browser and cross platform jQuery plugin to create HTML textarea element with line numbers. The plugin auto / dynamically insert number to each new line of textarea.

You just need to create a standard HTML textarea element, this jQuery plugin will automatically add numbering. You can also highlight specific line of textarea with color.

Plugin Preview

HTML Textarea with Line Numbers - jQuery Lined Textarea

Plugin Overview

Plugin: Lined Textarea
Author: Alan Williamson
Licence: MIT Licence
Published: June 16, 2023
Repository: Fork on GitHub
Dependencies: jQuery 1.3.1 or Latest version
File Type: zip archive (HTML, CSS & JavaScript )
Package Size: 5.89 KB

How to Make HTML Textarea with Line Numbers

1. Load the jQuery and lined-textarea ‘s CSS and JavaScript file into your HTML document.

2. Create a standard HTML textarea element with class name lined and add your text contents into it.

  

3. Finally, initialize the plugin in jQuery document ready function to active the textbox numbering.

4. If you want to highlight / select specific number in line, you can use the following option.

5. If you want to customize the styles, you can edit plugin’s CSS file. The default CSS styles are:

.linedwrap < border: 1px solid #c0c0c0; padding: 3px; >.linedtextarea < padding: 0px; margin: 0px; >.linedtextarea textarea, .linedwrap .codelines .lineno < font-size: 10pt; font-family: monospace; line-height: normal !important; >.linedtextarea textarea < padding-right:0.3em; padding-top:0.3em; border: 0; >.linedwrap .lines < margin-top: 0px; width: 50px; float: left; overflow: hidden; border-right: 1px solid #c0c0c0; margin-right: 10px; >.linedwrap .codelines < padding-top: 5px; >.linedwrap .codelines .lineno < color:#AAAAAA; padding-right: 0.5em; padding-top: 0.0em; text-align: right; white-space: nowrap; >.linedwrap .codelines .lineselect

I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.

Leave a Comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • 65+ Login Page in HTML with CSS Code Sample Simple to Difficult — 644,926 views
  • 25+ Best JavaScript Shopping Cart Examples with Demo — 130,879 views
  • Bootstrap Multiselect Dropdown with Checkboxes — 117,219 views
  • Bootstrap 5 Buttons with Icon and Text Tutorial & Demo — 89,771 views
  • 19+ Bootstrap Select Dropdown with Search Box Tutorial & Examples — 80,726 views
  • Bootstrap Vertical Menu with Submenu on Click — 64,300 views
  • 99+ Social Media Buttons HTML Code Sample & Tutorial — 62,178 views
  • Bootstrap 5 Sidebar Menu with Submenu Collapse/Hover Tutorial Demo — 61,354 views
  • Bootstrap 4 Modal Popup Login Form Tutorial & Demo — 57,501 views
  • 19+ Bootstrap 5 Mega Menu Responsive/Drop Down Examples — 50,158 views

Free Web Design Code & Scripts — CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners. find out more.

CodeHim
Top Categories
Get in Touch

Follow us on social media to be updated with latest web design code & scripts.

Источник

Оцените статью