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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:15:35+00:00 2026-06-12T19:15:35+00:00

I have a form that I want to validate before the user is able

  • 0

I have a form that I want to validate before the user is able to submit it. To do this I have written a basic js file that checks a value is not left blank. In the event that this is the case I want the background colour of the text field to update to be red. I have looked around online and am struggling to get this working. Here is what I have so far:

HTML Form:

<script language="javascript" src="validateForm.js"></script>
<form name="contact form">
    <input  type="text" name="name"></td>
    <input type="button" value="Send" onsubmit="return validateForm()" method="post">
</form>

Javascript:

function validateForm()
{
var result = true;
var form = document.forms["contact form"];

// Name
var name = form["name"].value;
if ( name == null || name == "" )
{
    form["name"].style.backgroundColor = red;
    result = false;
}

return result;
}

Please could someone help me get this working?

  • 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-12T19:15:36+00:00Added an answer on June 12, 2026 at 7:15 pm

    Use red as string ( you missed the quote) jsfiddle

    form["name"].style.backgroundColor = "red"; // not red
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that has target=_blank on submit. I want to validate the
I have a form that I want to be validated before showing it initially.
I have this select input in my form that I want to access via
I have a view file that looks like this: <?php echo $this->Form->create('ModelName'); echo $this->Form->input('ModelName.0.firstField');
I have written a set of javascript functions that allow me to validate user
I have a form that validates the email address and I want to be
I have a form that i want to appear at the top of every
I have a form that i want an administrator to fill out, then click
I have a form that i want to auto populate the last 2 fields
Okay all, I have a form that I want users to fill out. When

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.