Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 862779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:12:02+00:00 2026-05-15T09:12:02+00:00

I have set up a <textarea> and functions that will pick up keystrokes. I

  • 0

I have set up a <textarea> and functions that will pick up keystrokes. I have it set up where if the user presses Enter, the text typed in the text area will be submitted to a database.

However, I want to prevent from submitting empty text, just pressing Enter and submitting. I also noticed that when Enter, a new line is created, so I can’t just check if the text is “” or if its length is 0 because the second time around there will be a new line.

The jQuery for detecting using the keyboard is:

$(document).ready(function(){
    $('.active-buddy-tab div#chat-window form#chat-message textarea#message').live('keydown', function(event) {

        var key = event.which;

        // all keys including return
        if (key >= 33) {

            var maxLength = $(this).attr("maxlength");
            var length = this.value.length;

            if (length >= maxLength) {
                event.preventDefault();
            }
        }
    });

    $('.active-buddy-tab div#chat-window form#chat-message textarea#message').live('keyup', function(e) {

        if (e.keyCode == 13) {

            var text = $(this).val();
            var maxLength = $(this).attr("maxlength");
            var length = text.length;

            var to = $('.active-buddy-tab div h3 p#to').text();

            if (length <= maxLength + 1) {
                chat.send(text, from, to);
                chat.update(from, to);
                $(this).val("");
            } else {
                $(this).val(text.substring(0, maxLength));
            }

        }
    });
});

So how can I prevent from sending an empty message? I apologize if this is really simple, maybe I’m thinking too hard about this.

Thanks,
Hristo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:12:02+00:00Added an answer on May 15, 2026 at 9:12 am
    if( $.trim( $(this).val() ) == "" ) // empty
    

    trim

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jquery post that takes text from a textarea and inputs it
I have a form with a textarea. Users enter a block of text which
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I have multiple table rows that has a set of radio buttons on each
I am creating a survey form that needs to have each question and set
I'm writing a small web app that will receive and parse tab-delimited text files
I have some code that when a user clicks on a link Add Comment,
I have a form that consists of: 3 text boxes (first two are required
I want to select every textarea that does not have a DIV with class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.