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

The Archive Base Latest Questions

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

I am having trouble getting this validation to work. I am validating that a

  • 0

I am having trouble getting this validation to work. I am validating that a selectbox has been chosen and not left on the default option within my form.

Form:

<label for="reason">How can we help?</label>
   <select name="reas">
    <option value="Please Select">Please Select</option>
    <option value="Web Design">Web Design</option>
        <option value="branding">Branding</option>
        <option value="rwd">Responsive Web Design</option><span id="dropdown_error"></span>
  </select>

Onclick event:

$(document).ready(function(){
    $('#contactForm').submit(function(){
        return checkSelect();
    });
});

Function:

function checkSelect() {
    var chosen = "";
var len = document.conform.reas.length;
var i;

for (i = 0; i < len; i++){
        if (document.conform.reas[i].selected){
            chosen = document.conform.reas[i].value;
        }
 }

    if (chosen == "Please Select") {
    document.getElementById("dropdown_error").innerHTML = "No Option Chosen";
        return false;
    }
    else{
    document.getElementById("dropdown_error").innerHTML = "";
    return true;
    }
}

I also get this error in the console:

Uncaught TypeError: Cannot set property 'innerHTML' of null 

I am really new to javascript, so, I am learning and trying some simple examples at the moment, but I cannot see what is causing this not to validate.

Any help appreciated

  • 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:47:36+00:00Added an answer on June 12, 2026 at 6:47 am

    First, you can’t have your error span inside the <select>. Move it outside of the <select> HTML, and that will make the JS error go away.

    <label for="reason">How can we help?</label>
    <select name="reas">
        <option value="select">Please Select</option>
        <option vlaue="Web Design">Web Design</option>
        <option vlaue="branding">Branding</option>
        <option vlaue="rwd">Responsive Web Design</option>
    </select>
    <span id="dropdown_error"></span>
    

    Then, since you are already using jQuery, you could shorten your whole validation function to just this:

    function checkSelect() {
        var chosen = $('select[name="reas"]').val();
        if (chosen == "select") {
            $("dropdown_error").text("No Option Chosen");
            return false;
        } else {
            $("dropdown_error").text("");
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having trouble getting this to work. I'm writing a Vim snippet that will
I am having trouble getting this invisibilityOfElementLocated() method to work. Here is the code
Ok this seems so silly but I'm having some trouble getting this to work.
I'm having trouble getting this script to work. <asp:DropDownList CssClass=workUnit Width=80 ID=dropdownWorkUnit runat=server Visible=false
I'm having trouble getting this to work...it just replaces the entire page with the
I'm having trouble getting the Jquery Validation to work with the following rules. I
I have been having trouble getting this plugin to attach correctly to ajax loaded
I am learning python and am having trouble getting this program to work correctly.
I've done this before, but I'm having trouble getting this to work... I need

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.