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 8939305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:47:49+00:00 2026-06-15T10:47:49+00:00

So I wrote this code so that every time someone clicks the submit button,

  • 0

So I wrote this code so that every time someone clicks the submit button, a javascript
function, called check, will see if the text area is empty. If it is not, then the form will be submitted.
This is my code. Why isn’t it working?

<form method=post name='form_post' id='form_post' action='SUBMITIT.PHP'>
<textarea   id=message name=message class=post onfocus=this.className='post_focus';                                      
placeholder='Share your thoughts'  maxlength=500></textarea>
<br>
<button onclick='check()' id=button name=button>Post</button>
</form>


<script type="text/javascript"> 
function check() 
{ 
if(!document.textArea.message.value=="") 
{ 
document.forms["form_post"].submit();
}
} 
</script>

Thanks!

EDIT: I finally got it to work. Here’s a template if you are having a similar problem.

<!--The form-->
<form action="mypage.php" method="post" name="myForm" id="myForm">
<textarea name=myTextArea id=myTextArea>
</textarea>
</form>
<br>
<button onclick='check()'>
Post
</button>

<!--The script that checks-->
<script type="text/javascript"> 
function check(){ 
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }; 
var textAreaValue=document.getElementById('myTextArea').value; 
var trimmedTextAreaValue=textAreaValue.trim(); 
if(trimmedTextAreaValue!="") { 
document.forms["myForm"].submit(); 
} 
} 
</script>
  • 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-06-15T10:47:50+00:00Added an answer on June 15, 2026 at 10:47 am

    The following woks, and it also wipes unnecessary spaces, the form will only submit when given a character

    <form action="yourpage.php" method="post" onsubmit="return check(this)">
        <textarea id="message"></textarea>
        <input type="submit" value="Post" />
    </form>
    <script>
    function check(form){
        if (form.message.value.trim() == ""){
            return false
        }
    }
    </script>
    

    This is the most simple way to do this, and the advised one.

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

Sidebar

Related Questions

I need to write an application that will check for something every X time
Hopefully, this will be an easy answer for someone with Javascript time behind them...
I wrote this code that compiles on Solaris gcc it works fine too for
I wrote this piece of code that is supposed to redirect something written on
I have a program I wrote in Windows with this piece of code that
How to write this JavaScript code without eval? var typeOfString = eval(typeof + that.modules[modName].varName);
this is my first time writing script for cron job. I wrote my code
this is my code that I write it but I want to use LINQ
I'm trying to write a code that could print something like this -xv -xvv
I want to write a line of code that returns a pointer to this

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.