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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:22:42+00:00 2026-06-17T05:22:42+00:00

I am having trouble displaying strings depending on the if/else statements in my validation.

  • 0

I am having trouble displaying strings depending on the if/else statements in my validation.

If you look at the code below, if the if statement is met, then it displays the message which is fine, but then when I make sure the if statement is met and deliberately fail the else if statement, instead of displaying a message, it just displays a blank. Why is it not displaying a message for when else if statement is met in javascript validation below:

function editvalidation() {
     var isDataValid = true;
     var currentAssesO = document.getElementById("currentAssessment");
     var noStudentsO = document.getElementById("addtextarea");
     var studentAssesMsgO = document.getElementById("studentAlert");

     studentAssesMsgO.innerHTML = "";

     if (currentAssesO.value == ""){
         $('#targetdiv').hide();
         studentAssesMsgO.innerHTML = "Please Select an Assessment to edit from the Assessment Drop Down Menu";
         isDataValid = false; 
     }else if (noStudentsO.value == ""){
         $('#targetdiv').hide();
         studentAssesMsgO.innerHTML = "You have not Selected any Students you wish to Add into Assessment";
         isDataValid = false; 
     }
     else{
         studentAssesMsgO.innerHTML = ""; 
     }

     return isDataValid;
}

UPDATE:

HTML:

SELECT BOX (Options are appended into this box):

<select multiple="multiple" name="addtextarea" id="studentadd" size="10">
</select>

DROP DOWN MENU:

<select name="session" id="sessionsDrop">
<option value="">Please Select</option>
<option value='20'>EWYGC - 10-01-2013 - 09:00</option>
<option value='22'>WDFRK - 11-01-2013 - 10:05</option>
<option value='23'>XJJVS - 12-01-2013 - 10:00</option>
</select> </p> 

ALERT MESSAGE:

<div id='studentAlert'></div>

Reuirements for validation:

  • If drop down menu is empty, then display message that assessment needs to be select from drop down menu in alert message div.

  • If drop down menu is not empty, then check to see if the select box contains any options, if select box contains no options, then replace div alert message stating no students have been selected to add to assessment

  • If drop down menu is not empty and select box is not empty (or in other words contains an option), then div alert message is just an empty string ""

  • 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-17T05:22:44+00:00Added an answer on June 17, 2026 at 5:22 am

    Rephrase your JavaScript this way:

    function editvalidation() {
        var isDataValid = true;
        var currentAssesO = document.getElementById("currentAssessment");
        var noStudentsO = document.getElementById("addtextarea");
        var studentAssesMsgO = document.getElementById("studentAlert");
        var errorMsg = "";
    
        studentAssesMsgO.innerHTML = "";
        if (currentAssesO.value == "" || noStudentsO.value == "") {
            $('#targetdiv').hide();
            isDataValid = false; 
    
            if (currentAssesO.value == "") {
                errorMsg += "Please Select an Assessment to edit from the Assessment Drop Down Menu";
            }
    
            if (noStudentsO.value == "") {
                errorMsg += "You have not Selected any Students you wish to Add into Assessment";
            }
    
            studentAssesMsgO.innerHTML = errorMsg; // Plus whatever styling for messages.
        }
    
        return isDataValid;
    }
    

    Updated answer

    Please include jQuery by putting this in the <head> section.

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    

    Update your script:

    function editvalidation()
    {
        if ($("#sessionsDrop").val()=="")
            $("#studentAlert").html("Assessment needs to be filled.");
        if ($("#sessionsDrop").val()!="" && $("#studentadd").children().length==0)
            $("#studentAlert").html("No students have been selected to add to assessment.");
        if ($("#sessionsDrop").val()!="" && $("#studentadd").children().length!=0)
            return true;
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble displaying my mysql table using php code. All it displays is
I am having trouble displaying to my console to make my results look like
I'm having some trouble with displaying results from a datasource. This code will show
I am having trouble displaying results recieved from asp.net WebMethod. I have a HTML
I am having trouble displaying a raw YUV file that it is in NV12
I am having trouble displaying Date s in the format I want in my
I am having trouble displaying an background image in my ASP.NET MVC 2 application.
I'm having trouble with displaying image from db. I think that method for saving
I am having trouble passing the return value from TheMethod() to Main and displaying
I am having trouble with array_push. It is displaying Parse error: syntax error, unexpected

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.