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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:47:59+00:00 2026-06-15T08:47:59+00:00

I have a code below where it contains a form which contains text inputs

  • 0

I have a code below where it contains a form which contains text inputs a drop down menu:

$editsession = "
    <form id='updateCourseForm'>

        <p><strong>Current Course Details:</strong></p>
        <table>
        <tr>
        <th>Course ID:</th>
        <td><input type='text' id='currentCourseNo' name='CourseNocurrent' readonly='readonly' value='' /> </td>
        </tr>

        </table>
        <div id='currentAlert'></div>

        <p><strong>New Course Details:</strong></p>
        <table>
        <tr>
        <th>Course ID:</th>
        <td><input type='text' id='newCourseNo' name='CourseNoNew' value='' /> </td>
        </tr>
        </table>
        <div id='newAlert'></div>

        </form>

        <p id='submitupdatebtn'><button id='updateSubmit'>Update Course</button></p>

    ";

    echo $editsession;

Now I want to validate the form using Javascript and below is the code for the javascript validation:

function editvalidation() {

var isDataValid = true;

var currentCourseO = document.getElementById("currentCourseNo");
var newCourseNoO = document.getElementById("newCourseNo");

var currentCourseMsgO = document.getElementById("currentAlert");
var newCourseMsgO = document.getElementById("newAlert");


if (currentCourseO.value == ""){
currentCourseMsgO.innerHTML = "Please Select a Course to edit from the Course Drop Down Menu";
$('#newAlert').hide();
isDataValid = false; 
}else{
currentCourseMsgO.innerHTML = ""; 
}


if (newCourseNoO.value == ""){
newCourseMsgO.innerHTML = "Please fill in the Course ID in your Edit";
$('#newAlert').show();
isDataValid = false;
} else{
newCourseMsgO.innerHTML = ""; 
}


return isDataValid;

}

Now this is the problem I am getting:

What I am trying to state in my javascript validation is that if the #currentCourseNo is empty (text input is blank), then it displays the error message for this which belongs to the div tag #currentAlert, but it hides messages which are displayed in the div tag #newAlert. If the #currentCourseNois not empty then show the #newAlert error messages if there are any.

The problem I am having is that it is still showing the #newAlert error messages when the #currentCourseNo text input is empty, when it really should be hidden. What needs to be changed in the javascript above in order to achieve what I want to achieve?

  • 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-15T08:47:59+00:00Added an answer on June 15, 2026 at 8:47 am

    First, learn about jQuery.

    For your process, my common flow is to add a first pass of validation on the blur event of the inputs, and a second (exactly the same) pas of validation on the submit event of the form, something like :

    var error = $('.errormsg');
    
    var checks =
    {
      "fieldName1": function(val) { return /*true or an error string*/ },
      "fieldName2": function(val) { return /*true or an error string*/ }
    };
    
    $('input')
    .focus(function()
    {
      $(this).removeClass('error');
    })
    .blur(function()
    {
      error.slideUp(200);
    
      var check = checks[this.name];
      if (!check) { return; }
    
      var validation = check(this.value);
    
      if (typeof validation === "string")
      {
        $(this).addClass('error');
        error.text(validation).slideDown(200);
      }
    });
    
    $('form').submit(function(e)
    {
      //e.preventDefault();
    
      if ($('input.error').length != -1)
      {
        error.text('All fields are required').slideDown(200);
        return;
      }
    
      for(var check in checks)
      {
        var field = $('input[name="' + check + '"]');
        if (field.length == -1) { continue; }
    
        var validation = check(field.val());
    
        if (typeof validation === "string")
        {
          field.addClass('error');
          error.text(validation).slideDown(200);
          return;
        }
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The form below can contains different elements of text fields, drop down and selection
I have the below code for my a Dialog box for a which contains
I have this page (code below) which contains a series of 5 checkboxes, all
Form contains two dropdown lists created using code below. Both dropdown list elements have
The code below works great. I have a MySQL database that contains book titles
I have the code below which I use clone() and live() . The code
I have a page in JQuery mobile, which contains a form. The form has
I am new in phonegap .I have two text field which contains mobile n.
I have a form which contains a whole bunch of checkboxes and some other
I have an asp.net content form which contains a couple of textboxes. 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.