Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Javascript: Textarea maxlength and carrying over extra characters

Featured Replies

Alright, so I've already pestered this forum with a couple questions already, but I (hopefully) have one last problem that I can't seem to find any tutorials or information on...

 

I have two text areas, each which need a maximum length of 200 characters.

 

I would like it so that when the character limit is exceeded on the first text area, it spills over into the second.

 

I should also note, these text areas are being populated by the values of other text inputs, using the following Javascript:

 

<script type="text/javascript"> 
<!-- 
var textB1 = "value one: " ; 
var textB2 = "value two: "; 
var space = "\n";
  
function xferText() { 
    document.getElementById("textB").value=textB1 + document.getElementById("text").value +space +textB2 +document.getElementById("textA").value; 
} 
  
window.onload = function() { 
  document.getElementById("textB").value=textB1 + textB2; 
} 
//--> 
</script> 

 

And the HTML:

<div> 
    <input type="text" id="text" />
</div> 

<div>
<input type="text" id="textA" />

<div> 
    <textarea id="textB"></textarea> 
</div> 

<div> 
    <textarea id="textC"></textarea> 
</div> 

</div>
<button onclick="xferText();">Transfer Text</button>
</div>

Edited by wellerweb

What you essentially need to do is put together a string with that combination of values, check it's length and if it's too long, populate a second string with the extra bit before reducing the size of the first string.

 

I've put together an example showing how to do this, feel free to use it: Skateside's example

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.