A management section featuring fields where you can update the feline's name, URL, and click count (initially concealed)

I set up an HTML form with an Admin Button, and in the .js file, I added a click Event to the Admin Button to switch from:

style='display:none'

to:

style='display:block'

However, it seems like this change is not taking effect. Why?

var adminMode = {
  init: function() {
    this.adminButton = document.getElementById('admin-button');
    this.adminForm = document.getElementById('admin-form');// form ID   
    this.allForm = document.getElementById('all-form'); //div ID

    this.adminButton.addEventListener('click', function (allForm) {
      this.adminForm.style.display = 'inline';
    });
  },

HTML

<button id='admin-button'>Admin</button> <br><br>
<div id='all-form'>
 <form id='admin-form' style='display:none'>
   Name:<br>
     <input type="text" name="firstname" value=" "> <br><br>
   Img URL:<br>
    <input type="text" name="lastname" value=" "> <br><br>
    <button> Save</button>
    <button>Cancel</button>
 </form>
</div>

Answer №1

let dashboardMode = {  initialize: function() {      
    this.dashboardButton = document.getElementById('dashboard-button');   
    //this.dashboardForm =   document.getElementById('dashboard-form');// form ID
    //this.allForm =  document.getElementById('all-form'); //div ID 
    this.dashboardButton.addEventListener('click', function (event) {
        document.getElementById('dashboard-form').style.display = 'block'   
});

},

Answer №2

Do you understand?

 init: function() {
    document.getElementById('admin-button').addEventListener('click', function () {
          document.getElementById('allForm').style.display = 'block';  
     });
    }

OR admin-form

 init: function() {
    document.getElementById('admin-button').addEventListener('click', function () {
          document.getElementById('admin-form').style.display = 'block';  
     });
    }

If you use function(), the context is not recognized....

For your Revision: place the function in a script tag instead of init()

function showForm(){
  document.getElementById('admin-form').style.display = 'block';  
}
<button id='admin-button' onclick="showForm()">Admin</button> <br><br> 
<div id='all-form'> 
 <form id='admin-form' style='display:none'> 
   Name:<br>
     <input type="text" name="firstname" value=""> <br><br>
   Img URL:<br> 
    <input type="text" name="lastname" value=""> <br><br> 
    <button> Save</button>  
    <button>Cancel</button> 
 </form> 
</div>

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

Aligning Material-UI Text Field with a Paragraph

I'm currently working on a React app that has a "mad-libs" style and I'm facing some challenges trying to align a couple of components. The image below shows the current situation along with an arrow pointing to the desired outcome. It seems like ...

How is it possible that TypeScript does not provide a warning when a function is called with a different number of arguments than what is expected?

I am working on a vanilla JavaScript project in VS Code and have set up jsconfig.json. Here is an example of the code I am using: /** * @param {(arg: string) => void} nestedFunction */ function myFunction(nestedFunction) { // Some logic here } myFu ...

Storing additional data from extra text boxes into your database can be achieved using AJAX or PHP. Would you

A dynamic text box has been created using Jquery/JavaScript, allowing users to click on an "Add More" button to add additional input boxes for entering data. However, a challenge arises when attempting to store this user-generated data in a database. Assi ...

Can you provide some instances of attribute directives?

I'm struggling to understand when it's best to implement an attribute directive, know when an attribute directive is necessary, utilize input and output properties Why should I use an attribute directive? I often find myself combining all l ...

Ratios for Sizing Bootstrap Columns

The Bootstrap grid system consists of 12 columns in total. I am looking to utilize all 12 columns on the page. However, my goal is to have the first 6 columns on the left side be half the width (50%) of the columns on the right side. This means that the ...

Encountering a permission error when attempting to save the index.php file?

We encountered an issue when trying to save the index.php file on FileZilla. The error message displayed was: Error: /home/devratnacricket/public_html/admin/index.php: open for write: permission denied Error: File transfer failed What steps should we t ...

Tips on concealing JavaScript values from being detected during web inspection

I need to securely pass a secret code from my backend to the front end and store it in my JavaScript script. Here is an example of how I want to achieve this: <script> var code = '<%= code %>' </script> Once the us ...

What is the best way to combine a string that is constructed across two separate callback functions using Mongoose in Node.js?

I am facing a situation where I have two interconnected models. When deleting a mongo document from the first model, I also need to delete its parent document. There is a possibility of an exception being thrown during the second deletion process. Regardl ...

Creating numerous Facebook posts using jQuery technology

I am currently facing a challenge when attempting to publish multiple facebook posts on a webpage using jQuery. Although I have managed to successfully post the first facebook post, I am encountering difficulties when trying to post another one. What coul ...

Transform the date to the momentjs format: 2019-05-31T12:08:04Z

Can someone provide instructions on using momentjs to convert a date into the format 2019-05-31T12:08:04Z? Also, could you clarify what format this is? ...

Potential unhandled promise error in react-native

When I use the code below, it produces a "Possible unhandled promise rejection" error: constructor(props){ super(props) DatabaseHandler.getInstance().getItems(function (items) { console.log(items)//successfully print data ...

Expand the width of the dynamic arc surrounding the circle

I borrowed an animated circle with a timer. I need to adjust the width of the animated arch within the circle. Can someone help me do this? I'm having trouble figuring it out on my own. You can access the jsFiddle here This is where I have set the ...

Filtering data from nested arrays in MongoDB

My data structure and schema are as follows: { date: 0, darwin: [ { d: ['string1', 1, 0, 0, 0] }, { d: ['string2', 1, 0, 0, 0] }, { d: ['string3', 1, 0, 0, 0] } ] } I'm try ...

What could be causing the inability to apply CSS to customize form content?

I've just wrapped up creating a sign-up form, but I seem to be having trouble utilizing display:inline-block. What could possibly be the issue? The internal elements are stubbornly glued together and refuse to budge. (On another note, any suggestio ...

Embracing the power of VueJS with a Bootstrap template

After working on a VueJS website for a while, I realized that my design skills weren't up to par when it came to creating an effective landing page. That's when I stumbled upon this amazing Bootstrap open source template that I really want to inc ...

Create an Express.js module that includes two routes for user signup and signin

Seeking assistance on merging various functions such as sign up, sign in, delete a profile, edit profile into a single file named Users within express. Currently, I have set up sign up under '/', but I am unable to navigate to the sign in functi ...

Provide net.socket as a parameter

What is the best way to pass the net.socket class as an argument in this scenario? Here's my code snippet: this.server = net.createServer(this.onAccept.bind(this)); this.server.listen(this.port); } Server.prototype.onAccept = function () { // Ho ...

Discovering if a web element includes a pseudo element in Java

Within my Java Selenium automation project, I am faced with the challenge of determining whether certain web elements contain pseudo elements or not. I came across this question but found that the provided answer does not work as expected. This solut ...

Retrieving data from the text area when it comes into view

I am currently working on a blog-like portfolio and I want the content of the posts to only be loaded when they are viewed. To achieve this, I have been experimenting with storing the HTML code in a textarea temporarily and then placing it within a div whe ...

Retrieve a data value from a JSON object by checking if the ID exists within a nested object

I am facing the challenge of navigating through a JSON object where child objects contain IDs that need to be matched with parent properties. The JSON structure looks like this: { id: 1, map: "test", parameter_definitions: [{ID: 1, pa ...