Concealing a div based on a condition

Having difficulty concealing a div once a specific condition is met. The condition depends on the user logging into a web application.

In my CSS file, I have set the multipleBox div to visibility: hidden, along with other styling attributes like border color.

Attempted using a function in Ajax to manipulate the display/visibility of the div based on the logged-in user. Unfortunately, it didn't work as expected.

Tried changing the div class using JavaScript as well, but no success there either.

The current function that's giving me trouble is triggered onload of the body:

function Hidder() { var valid = document.getElementById("form1:validate").value;

if (valid == true) {

    document.getElementById("multipleBox").style.visibility ="visible";
    }

}

Couldn't successfully toggle between visibility or display settings.

I aim for the div to remain hidden unless the user accessing the web app is an admin. I utilized JSF tags in my JSP page to fetch the user's credentials, storing the boolean value in the 'valid' variable.

Answer №1

It seems that accessing an element by ID using

document.getElementById("form1:validate").value
may not be the correct method.

You could try using

document.getElementById("validate").value
if 'validate' is indeed the ID of your input field with the boolean value.

Another option is to retrieve the value by form name and field ID, like so:

document.querySelector("form[name=formname] #validate").value

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modify the width of the <nz-date-picker> component from Ng-Zorro

Currently using Ng-Zorro for my template styling and working on implementing a date picker that I want to align perfectly with the dropdown menu above it. I would like to adjust the width of the date-picker manually within the template, but after visiting ...

The functionality of Flatbutton(Input handler) appears to be malfunctioning

I am having trouble with the file uploader from Material-UI. It doesn't seem to be working properly when I try to select a file. Does anyone have any suggestions on how to handle the input from the file selector? <FlatButton icon={< ...

Enhance your images with Jquery thumbnail zoom feature

I am in the process of creating color swatches for clothing items, using them as a reference point. http://jquery.malsup.com/cycle/pager7.html Take a look at the thumbnails on the webpage mentioned above. My goal is to display these thumbnails without re ...

The website does not support the zoom out or scrolling features on iOS devices

A portion of our website has been optimized for mobile devices, however, we have decided to direct iPhone users to the desktop version when accessing the Blogs section (all PHP content) at this time. While this functions properly on an iPad, we have encou ...

Integrating md-chips md-separator-keys with md-autocomplete: A step-by-step guide

My experience with using md-chips and md-autocomplete reveals an issue: when I incorporate md-separator-keys, it functions as expected. However, upon adding md-autocomplete, the md-separator-keys functionality ceases to work. This is how my code is struct ...

Mastering the art of configuring AngularJS: A beginner's guide

Exploring the world of angularJS, I have encountered the config function which presents two different argument structures as shown in the following example. Example 1 dashboardApp.config(function($stateProvider, $urlRouterProvider) { //$urlRouterProvider ...

Obtaining a complete element from an array that includes a distinct value

I'm attempting to retrieve a specific item from an array that matches a given value. Imagine we have an array const items = ["boat.gif", "goat.png", "moat.jpg"]; We also have a variable const imageName = "boat" Since we don't know the file ex ...

Angular does not display results when using InnerHtml

I'm currently in the process of creating a weather application with Angular, where I need to display different icons based on the weather data received. To achieve this functionality, I have developed a function that determines the appropriate icon to ...

Prevent any further dissemination if I continue typing repeatedly

As I develop a custom search engine for a website, the search functionality operates through AJAX on keyup events. This means that when you begin typing (assuming you type more than two characters and after any leading or trailing spaces are removed), an A ...

Encountered an error when attempting to load resource: net::ERR_CERT_AUTHORITY_INVALID following deployment on Vercel

I recently deployed a chatUI-app on Vercel that fetches chats from an API located at "http://3.111.128.67/assignment/chat?page=0" While the app worked perfectly in development, I encountered an issue after deploying it on Vercel where it ...

Creating a custom npm package for a specific project

As I work on an npm package named my-library and regularly publish updates to a private npm repository, how can I efficiently test changes without repeatedly releasing new versions? Consider the following scenario: I tweak the code in my-library, but wan ...

What is the mechanism for invoking functions defined with the arrow syntax in Angular?

Referencing this code snippet from the tutorial at https://angular.io/tutorial/toh-pt4, specifically within the hero.component.ts file: getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes => this.heroes = heroes); } After analyz ...

HTML elements not displaying in Ajax form

I am encountering an issue with my ajax based feedback form where the form is displaying the html from the response instead of processing it correctly. Here is the JQuery code: $(document).ready(function() { var form_holder = $('#form-holder'); ...

What is causing find_by_css to return nothing when using nth-child?

Currently, I am facing an issue when trying to extract the "href" link from the following HTML code: https://i.stack.imgur.com/Gtzf4.png This is the code that I'm using: from selenium import webdriver from splinter import Browser from bs4 import Be ...

Innovative solution for detecting and replacing undefined object properties in Angular 2 with TypeScript

After encountering the issue of core.umd.js:3523 ORIGINAL EXCEPTION: Cannot read property 'fullName' of undefined I realized that the Exception stemmed from a Template trying to access a specific property: {{project.collaborators["0"]["fullN ...

Is it possible to return an array of middleware from one middleware to another in Express JS?

Looking to display shop information through a route. The route setup is as follows: router.param('userId',getUserById) router.get("/store/:storeName/:userId?",isAuthenticated,getStoreDetail) My goal is to send different responses based ...

When the text exceeds its container, the CSS property overflow will display only the

.example{ overflow:auto; } <div class="example"> <p>Some Additional Text Here<P> </div> This particular code snippet showcases the initial portion of the text, allowing for scrolling down to reveal items 5 and 6: 1 2 ...

What is the best way to fetch JSON data in the backend of my code?

I have a json (id) being sent to "page2.aspx" from "page1.aspx". This is the code in my Page1.aspx: (function load() { return $.get("page2.aspx", {id: "123" }, function (response, status, xhr){ //code } } How can ...

What is the best way to eliminate unexplained spacing at the bottom of a webpage using CSS?

I am struggling to create a basic webpage using Bootstrap and D3, and I can't seem to figure out how to remove the excess whitespace at the bottom. Any tips on how to resolve this issue would be greatly appreciated. I attempted to set the min-height ...

Prevent selection of rows in the initial column of DataTables

I am working on a basic datable, the code can be found here JS: var dataSet = [ ["data/rennes/", "Rennes", "rennes.map"], ["data/nantes/", "Nantes", "nantes.map"], ["data/tours/", "Tours", "tours.map"], ["data/bordeaux/", "Bordeaux", ...