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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:14:10+00:00 2026-05-30T12:14:10+00:00

Hey Guys in the below code every time the if statement is executed no

  • 0

Hey Guys in the below code every time the if statement is executed no matter what the condition is.

function addRow(tableID) {

            var table = document.getElementById(tableID);
            if((document.getElementById('select_degree').style.visibility = 'hidden')&&(document.getElementById('select_degree')!=null)){
              document.getElementById('select_degree').style.visibility = 'visible';
              document.getElementById('select_ratings').style.visibility  = 'visible';
             }

            else{ 
            var rowCount = table.rows.length;
            var new_row = table.rows[rowCount-1];  


            var row = table.insertRow(rowCount);


            var colCount = table.rows[0].cells.length;




            for(var i=0; i<colCount; i++) {

                var newcell = row.insertCell(i);


                newcell.innerHTML = new_row.cells[i].innerHTML;
            }
           }             
        }

When document.getelementById(‘add_degree’) is null I get the error:

document.getElementById("select_degree") is null
addRow(tableID="add_degree")

But I already have a else statement if the element is null

  • 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-05-30T12:14:11+00:00Added an answer on May 30, 2026 at 12:14 pm

    Your if statement is not using the correct operator. Replace your = (used for assignment) with the comparison operator: ==. In addition, you must check if the element exists before attempting to check it’s properties. If you don’t, you’ll get an exception when the element doesn’t exist.

    Here is your code, corrected and cleaned up:

    function addRow(tableID) {
        var objSelectDegree = document.getElementById('select_degree');
        if (objSelectDegree != null && objSelectDegree.style.visibility == 'hidden') {
            objSelectDegree.style.visibility = 'visible';
            document.getElementById('select_ratings').style.visibility = 'visible';
        }
        else {
            // Moved table var to else block - it was not used unless else was hit
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
            var new_row = table.rows[rowCount - 1];
            var row = table.insertRow(rowCount);
            var colCount = table.rows[0].cells.length;
    
            for (var i = 0; i < colCount; i++) {
                var newcell = row.insertCell(i);
                newcell.innerHTML = new_row.cells[i].innerHTML;
            }
        }
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, i have very small issue please see the code below // this
Hey guys, attached below is my code, and then my CSS. They item fades
Hey guys i want to execute my SQL statement but im having synatx trouble,
Hey Guys, here is my code for this, the only help i get from
Hey guys, I'm writing a word wrap function to format console text in C++.
Hey guys I have an ajax jquery function that receives data from a php
Hey guys this is a snippet of my current code. I want to know
Hey guys i have been trying to download it from the below link http://www.enterprisedb.com/products-services-training/pgdownload
Hey guys, I want to make a function loop over all elements that have
Hey guys I have a gridview and below it 4 textboxes I'm using to

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.