• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Opening and closing a modal dialog using JavaScript

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Trying to create a page with a responsive sidebar. Just to clarify, I want the menu to appear or disappear at the push of a button.
I've messed around with this for a while, and came up with a modal dialog. However, the button I use to open it doesn't seem to work.
Here's the button code:
   <button onclick = "menuButton()" > Menu</button>
In theory, this should open the modal dialog containing the menu. Here's the associated JavaScript:
  <script>
     const
 menuButton = document.getElementById('menubtn'),
 trueMenu = document.getElementById('true-menu'),
 closeButton = document.getElementById('close-true-menu');

menuButton
 .addEventListener(
   'click',
   () => {
     trueMenu.showModal();
   }
);

closeButton
 .addEventListener(
   'click',
   () => {
     trueMenu.close();
   }
 );
  </script>
I've lost a lot of hair over this one, and any useful hints would be very much appreciated.
 
Saloon Keeper
Posts: 7633
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

This is not a complete, executable code example so it's hard to day what might be going wrong. The first step would be to check the browser's console for any error messages.
 
bacon. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic