I've tried google and this site but cant seem to find anywhere to start?
I'm trying to make a character limit one then automaticaly go to the next open text box.

Dani AI

Generated

Short practical answer: for web pages use the HTML maxlength attribute to enforce a client-side character cap, and a small JavaScript listener to move focus to the next available field when the cap is reached. pointed out that textboxes expose a maxlength-like setting and showed checking length server/desktop-side — the snippet below shows a browser-friendly approach that handles typing, pasting and IME composition.

<!-- HTML -->
<input id="part1" maxlength="3" data-next="part2" aria-label="Part 1">
<input id="part2" maxlength="3" data-next="part3" aria-label="Part 2">
<input id="part3" maxlength="4" aria-label="Part 3">

// JavaScript
(function(){
  var composing = false;
  document.addEventListener('compositionstart', function(){ composing = true; }, true);
  document.addEventListener('compositionend', function(){ composing = false; }, true);

  document.addEventListener('input', function(e){
    if (composing) return;
    var el = e.target;
    var max = el.getAttribute('maxlength');
    if (!max) return;
    if (el.value.length >= parseInt(max, 10)) {
      var nextId = el.dataset.next;
      var next = nextId ? document.getElementById(nextId) : findNext(el);
      if (next && !next.disabled && next.type !== 'hidden') next.focus();
    }
  }, true);

  function findNext(el){
    var list = Array.prototype.slice.call(el.form ? el.form.elements : document.querySelectorAll('input, textarea'));
    var i = list.indexOf(el);
    for (var j = i + 1; j < list.length; j++){
      var c = list[j];
      if ((c.tagName || '').toLowerCase() === 'input' || (c.tagName || '').toLowerCase() === 'textarea'){
        if (!c.disabled && c.type !== 'hidden') return c;
      }
    }
    return null;
  }
})();

Notes and troubleshooting: use the input event rather than key events so pastes and mobile IME behave correctly. Handle compositionstart/compositionend to avoid jumping focus while users are composing characters (important for CJK). Always validate again on the server — client-side limits improve UX but are not a security guarantee. For reference: HTML maxlength and InputEvent details on MDN (maxlength attribute, InputEvent, HTMLElement.focus).

Recommended Answers

All 2 Replies

Every textbox has a MaxLength property you could test for . Default it is set to 32767 chars.

I've tried google and this site but cant seem to find anywhere to start?
I'm trying to make a character limit one then automaticaly go to the next open text box.

Text boxes have a .Length API call which will tell you how many characters are currently in the text box. It looks something like this:

if(textBox1.Text.Length >= 50)
{
	MessageBox.Show("Invalid input. Value must be less than 50 characters");
}
else
{
      //Acceptable input length
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.