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

  • Home
  • SEARCH
  • 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 8378205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:52:34+00:00 2026-06-09T15:52:34+00:00

Trying to learn JavaScript, makin decent progress I guess, but I’m stuck at validating

  • 0

Trying to learn JavaScript, makin decent progress I guess, but I’m stuck at validating a form, tried to see if anybody has the same problem, search didn’t turn anything up. So would you please help me?

    var minlength = 6;
var pwlength = document.getElementById('psswrd');
var invalid = " ";

function validate() {

    if (pwlength.length < minlength && pwlength == invalid) {
        alert("Password not valid");

    else { 
        alert("Password okay!");
    }
}

submitbtn.onClick = validate();
  • 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-09T15:52:36+00:00Added an answer on June 9, 2026 at 3:52 pm
    • It is not obvious where you call this – I have wrapped it in a window.onload
    • you do not access the button correctly. Either of
      document.forms[0].submitbtn
      document.getElementById("submitbtn") or
      document.getElementsByName("submitbtn")[0] will work depending on how you name or ID the button HOWEVER do not assign onclick handlers to submit buttons, instead assign submit handler to the form
    • there is no point of testing for a single space since that is less than 6 chars anyway.
    • && is AND, you mean || OR
    • onclick must be all lowercase.
    • You assign the onclick to the result of validate instead of validate
    • You do not stop the submission

    I have taken the trim from here
    and I assume the form has ID=”form1″

    window.onload=function()
      document.getElementById("form1").onsubmit = validate;
    }
    
    if(typeof String.prototype.trim !== 'function') { // let's help older IEs
      String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, ''); 
      }
    }
    
    function validate() {
      var minlength = 6;
      var pw = document.getElementById('psswrd');
      if (pw.value.length < minlength || pw.value.trim() == "") {
        alert("Password not valid");
        pw.focus();
        return false;
      }
      return true; // allow submission  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to the javascript and ajax world but trying to learn. Right
I am trying to build a simple calculator to learn javascript/jquery but seem to
I'm trying to learn Javascript animations but, as I thinked, it doesn't work xD.
I am trying to learn JavaScript, but I'm struggling with a very simple example.
I am trying to learn JavaScript but I've come across a hurdle. If the
I am trying to learn making ajax calls using jQuery. But I am stuck
Trying to learn a bit of XUL but am a bit stuck. Building a
I am trying to learn JavaScript... I have function like, I take the format
I am trying to learn javascript i have this code: x=x.replace(/^\s+|\s+$/g,); can i have
Disclaimer: I am trying to learn javascript. I am not a clever man. So,

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.