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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:24:22+00:00 2026-06-12T06:24:22+00:00

I am trying to understand the function at (http://www.w3schools.com/js/js_form_validation.asp) and rework it (below) using

  • 0

I am trying to understand the function at (http://www.w3schools.com/js/js_form_validation.asp) and rework it (below) using getElementsByClassName to find a class attribute I added to an HTML input tag. I’m very new to Javascript, and I do not understand why I have to add .value (W3 example) or .view (my example) to the end of the statement below in order for it to work. As I understand it the first statement in the function says look in the document, and assign the variable X, to any input fields with the class attribute reqname.

Thank you.

MY FUNCTION:

function validateForm()
{
var x=document.getElementsByClassName("reqname").view;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}

FUNCTION AT W3:

function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}
  • 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-12T06:24:23+00:00Added an answer on June 12, 2026 at 6:24 am

    A form element such as an input field typically has a value, that is the string that has been entered into the input field.

    By specifying .value, they explicitly check whether the content of the element is null. Without it, they’d be checking if the element itself is null, i.e. if the element exists.

    Your code has some further issues. .view that you’re using doesn’t make sense. Also, getElementsByClassName returns a list of elements, rather than a single element, so you won’t be able to immediately access its .value.

    If you know that there’s just the one element, you could check getElementsByClassName("reqname")[0].value. If you want to validate the value of all “reqname” fields, you’d have to iterate over your collection and check each item individually:

    var elements =document.getElementsByClassName("reqname");
    for(var i = 0, l = elements.length; i < l; i++) {
       var x = elements[i].value;
       if(x == null || x == '') {
          alert("First name must be filled out");
          return false;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Revising code of jQuery.reveal plugin (http://www.zurb.com/playground/reveal-modal-plugin) and trying to understand how it handles the
http://www.indofolio.com/ , I'm trying to create a website with similar function to this one,
Trying to understand the Deezer API. When I visit: http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access I end up at
I'm using this Big Integer library for Javascript: http://www.leemon.com/crypto/BigInt.js and I need to be
im trying to follow this pretty good guide http://www.tylerbutler.com/2012/05/28/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/ but im getting the following
Javascript Ajax: <script type=text/javascript src=http://www.MyFirstDomain.com/jquery.js></script> <script type=text/javascript> $(document).ready( function () { var referrer =
I have a problem. I'm trying to integrate jQuery address http://www.asual.com/jquery/address/ into my website.
I am trying to follow what is being explained here: http://www.djangobook.com/en/2.0/chapter03/ (the confusing example
I am trying to understand function pointers and am stuggling. I have seen the
I'm trying to understand how php function usort works. I have such code: <?php

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.