Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to handle events in HTML?

As I understand it HTML is a mark-up language to easily exchange and render data on someone’s computer by the internet from other people’s computer.

It was a language that acts on DOM (Document Object Model) to provide some functionality to the other user like to render a webpage or handling events.

The problem with html is that when http request is made by a user to the http server, the http server will close the connection after it give the response to the user.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So, my question is what happen if the html file accepts a user input like onclick attribute of the html? does the event will be stored in a database somewhere like SQL, mongoDB or is it just purely DOM(meaning DOM can handle the event, like maybe DOM has its own database?)?

so let say if we want to navigate from one html file into another html file if the user click a button. But the in the first html file there is two buttons with its respective two images.

The second html file is the one to be rendered when clicking occur. How to make the second html file render the correct images based on the user input in the first html file? do I need a database? or does the event get stored in the DOM’s database if there is any.

>Solution :

Pass the respective image as a query parameter when navigating on page 2 as shown below.

<button onClick="page2.html?image=image1">Image 1</button>
 <button onClick="page2.html?image=image2">Image 2</button>

Read the query parameter on page 2 and render the image according to the value of query parameter. The query parameter can be read as below.

const queryString = window.location.search;

const urlParams = new URLSearchParams(queryString);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading