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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:26:36+00:00 2026-06-06T15:26:36+00:00

Can anyone see where I could be making a mistake? The form text-box background

  • 0

Can anyone see where I could be making a mistake? The form text-box background colors are originally set to grey. If the user makes a mistake I want to turn them yellow with a red border. The function is sort of working, because the form is not going to the server when the form is filled out incorrectly. But the css doesn’t change. If I comment out my js call it will post to the server. Here are the snippets:

CSS:

  .invalid{
background-color:#ff9;
border: 2px red inset;
}

   .reqd{
background-color:#222222; 
color:#555555; border-style: solid; 
border-color:#555555; 
border-width: 1px;
 }

HTML:

<!DOCTYPE html>
  <?php 
  // Debug
   error_reporting(E_ALL);
  ?>

<html lang="en">
 <head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles.css" type="text/css">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/regauth.js"></script>

    <title></title>
 </head>
 <body id="registerBody">
<section id="registerBox">

    <form id="registerForm" method="post" action="regauth.php">
    <p>Welcome to the atlas registraton! Please fill out the information below.</p>
    <br>
    <p><label for="firstName">First Name:&nbsp;&nbsp;<input type="text" size="30" id="firstName" name="firstName" class="reqd"></label></p>
    <p><label for="lastName">Last Name:&nbsp;&nbsp;<input type="text" size="30" id="lastName" name="lastName" class="reqd"></label></p>
    <p><label for="email">Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="30" id="email" name="email" class="reqd"></label></p>
    <br>
    <br>
    <p><label for="reqUsername">Username:&nbsp;&nbsp;<input type="text" size="30" id="reqUsername" name="reqUsername" class="reqd"></label></p>
    <p><label for="passOne">Password:&nbsp;&nbsp;<input type="password" size="30" id="passOne" name="passOne" class="reqd"></label></p>
    <p><label for="passTwo">Confirm Password:&nbsp;&nbsp;<input type="password" size="30" id="passTwo" name="passTwo" class="reqd"></label></p>
    <br>
    <br>
    <p><input type="submit" value="Submit">&nbsp;&nbsp;<input type="reset" value="Reset Form" class="reset"></p>

    </form> 
</section>
<script type="text/javascript">
$("#registerBox").css("margin-left", ($(window).width()-425)/2);
$("#registerBox").css("margin-top", ($(document).height()-500)/2);
$('#registerBox').fadeIn(1500);
</script>

   </body>

    </html>

JS (regauth.js): Courtesy of Tom Negrino, Visual Quickstart Guide: Javascript Eighth Edition

window.onload = initForms;

//Function loops through each form. For each one it adds an event handler to that forms 'onSubmit'.
function initForms() {
for (var i = 0; i < document.forms.length; i++) {
    document.forms[i].onsubmit = validForm;
     }
   }

function validForm() {
var allGood = true;
var allTags = document.getElementsByTagName("*");

for (var i = 0; i < allTags.length; i++) {
    if (!validTag(allTags[i])) {
        allGood = false;
    }
}
return allGood;

function validTag(thisTag) {
    var outClass = "";
    var allClasses = thisTag.className.split(" ");

    for (var j = 0; j < allClasses.length; j++) {
        outClass += validBasedOnClass(allClasses[j]) + " ";
    }
    thisTag.className = outClass;

    if (outClass.indexOf("invalid") > -1) {
        thisTag.focus();
        if (thisTag.nodeName == "INPUT") {
            thisTag.select();
        }
        return false;
    }
    return true;

    function validBasedOnClass(thisClass) {
        var classBack = "";

        switch (thisClass) {
            case "":
            case "invalid":
                break;
            case "reqd":
                if (allGood && thisTag.value == "") {
                    classBack = "invalid ";
                }
                classBack += thisClass;
                break;
            default:
                classBack += thisClass;
        }
        return classBack;
    }
}

}

  • 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-06T15:26:38+00:00Added an answer on June 6, 2026 at 3:26 pm

    Move the “invalid” CSS block to after the “reqd” one.

    The rules for CSS are that the “last rule wins” (sort-of; it’s more complicated but in this case that’s the issue).

    Even though the “invalid” rules apply to the invalid elements, because the “reqd” rule has a background color and because it comes after the “invalid” rule, that setting applies.

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

Sidebar

Related Questions

Can anyone see anything wrong with this login script: public function login($username, $pass, $remember)
My Get confirm isn't triggering the query? Can anyone see what I'm doing wrong?
Trying to convert the following but am having difficulty. Can anyone see where I'm
I'm at my wit's end with this. Can anyone see anything wrong with this
Can anyone see why i am getting the following error when i try to
Could anyone tell me / explain how can I make a proper test of
can anyone help me in trying to check whether JavaScript is enabled in client
Can anyone tell me whether Helvetica is a browser base font? If so, it
Can anyone recommend a good cheat sheet for gbd? I'm experienced with windbg commands,
Can anyone tell me why ActionScript 3, a statically typed language, doesn't have generics?

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.