Tips for closing a modal in JavaScript after submitting the form

As I try to learn JavaScript, I'm creating my Quiz game and encountering an issue with a modal window. After entering my nickname and pushing Submit, I want to save the nickname in localStorage and close the modal window. However, the problem is that the modal window keeps appearing again, preventing me from progressing to the main page of the quiz. If anyone has a different approach to achieving this in JavaScript, please share your insights. Initially, I considered having two HTML documents - index.html and nickname.html, but I got stuck when trying to change the URL using JavaScript after submitting the form. Any suggestions or guidance would be greatly appreciated. Thank you.

const enter = document.getElementById('enter');
const modal = document.getElementById('screen');

enter.addEventListener('click',function(){
    let forms =  document.forms["form-welcome"]["nickname"].value

    if(forms == ""){
        alert("Please write your nickname.");
        return false;
    }
    else{
        modal.style.display = "none";
        save();
        
    }
})
    function save(){
        localStorage.setItem(
            document.forms["form-welcome"]["nickname"].value
    
            );
    }
*{
    margin: 0px;
    padding: 0px;

}
body{
    background-color: red;
}
/*##### Window Modal #####*/
.wrapper{
    
    font-size: 24px;
    font-family:'Bree Serif', serif;
    text-align: center;

}
.modal{
    display: block;
    position: fixed;
    z-index: 1;
    left: 0;
    top:0;
    width:100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0,0,0);
    background-color: rgb(0,0,0,0.4);
}
.offModal{
    display: none;
}
.animate{
    -webkit-animation: animatezoom 0.6s;
    animation: animatezoom 0.6s;
}
.model{
    display: inline-block;
    margin-top: 25px;
    width: 30%;
    height: auto;
    background-color: #4edb0cfb;
    position: relative;
    border-radius: 25px;
    border:1px solid rgba(0, 0, 0, 0.267);
    box-shadow: 1.5px 1.5px rgba(0, 0, 0, 0.4);
    
}

.welcome{
    letter-spacing: 1px;
    position: relative;
    text-align: center;
    line-height: 50px;
    padding-top: 15px;
    margin-top: 15px;

}
.submit{
    border-radius: 5px;
    font-size: 30px;
    margin: 10px;
    padding: 10px;
}
.submit:hover{
    background-color: rgb(153, 150, 150);

}
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Final-Quiz</title>
    <link rel="stylesheet" href="reset.css">
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Bree+Serif&display=swap" rel="stylesheet">

</head>

<body>
    <div class="wrapper">

        <!-- FIST SCREEN -->
        <section>
            <div id="screen" class="modal">
                <form class="welcome model" name="form-welcome">
                    <h1>Final-Quiz</h1>
                    <label for="nickname">Nickname:</label>
                    <input type="text" name="nickname" required>
                    <input id="enter" class="submit" type="submit" value="Enter">
                    <p>Let's check your knowledge about HTML, CSS, and JavaScript.</p>

                </form>
            </div>
    </div>

    </section>
    </div>
    <script src="localStorage.js"></script>
</body>

</html>

Answer №1

Appreciation to all who helped me find a solution to my issue.

Within the tag, I inserted the action and url(); of the second HTML page.

<form action="secondHtml.html">

Upon submission, I am redirected back to the main page.

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

Locate a specific text within a complex array of objects and retrieve the objects that contain the match as

I have an array of objects named input as shown below. Each object in the array contains a property vertical of type string, an array called platformList, and a nested object named radar_metadata. I am looking to implement a search functionality where I c ...

The error message appears as "TypeError: json cannot be iterated

Encountering an Issue C:\Development\AlphaLauncher-Recode\app\assets\js\loggerutil.js:29 [Launcher] TypeError: json is not iterable at DistroIndex._resolveInstances (C:\Development\AlphaLauncher-Recode\app& ...

SSI stands for Server Side Includes, a feature that allows

I have multiple versions of the same HTML page, each with only one hidden variable that is different. This variable is crucial for tracking purposes. Now, I am exploring options to rewrite this by incorporating a HTML file with a hidden variable. Here is ...

Restricting the ability to uncheck jQueryCheckboxes

I have a unique scenario where I have two forms located in different tabs. Each crossover field has the ability to duplicate its value to the other form when there is a change in the field's content. In addition, I have implemented a feature where th ...

What is the best way to determine the number of lines within a textarea?

My goal is to accurately calculate the number of lines in a textarea, like so: line 1 line 2 line 3 line 4 which should equal 4 lines. Essentially, pressing enter once should create a new line. Unfortunately, the following code is not achieving this: v ...

Tips for splitting the json_encode output in Javascript

Looking for help with extracting specific values from JSON data retrieved via PHP and AJAX. I only want to display the agent name in my ID, not the entire object that includes "name" : "Testing". Here is the console output: [{"agent_module_id":"1","agen ...

Does the useState hook operate synchronously?

Previously, there has been a clear warning about the asynchronous nature of calling setState({myProperty}), where the value of this.state.myProperty is only valid after the callback or the next render() method. When using useState, how can I retrieve the ...

Leveraging the power of JavaScript functions together with the asp:Timer component

<p><b> Progress: <asp:Label ID="progressPercentageLabel" runat="server"></asp:Label>%</b></p> <script> function updateBar() { var bar = document.getElementById("CompletionBar"); ...

Guide to Generating a Dynamic HTML Menu

Is "dynamically" the correct term for what I'm trying to achieve? * I am looking to have a basic one-level menu appear on every one of the 80 pages on my website. The menu items will be updated regularly - some added, some removed, and so on. What is ...

Tips for deleting "Category: [category name]" in Wordpress

I have attempted various solutions found in previous threads, but none of them seem to work for me. Here is a screenshot I am looking to remove the text from the header in the category and only display [category name]. Can anyone assist me with this, ple ...

Struggling with passing parameters through a route and displaying them in the Reddit app using React?

I'm currently working on a project that involves displaying threads from various subreddits when a user clicks on a list item using routes and react. However, I've encountered some issues with getting the information to display correctly. Below i ...

I'm having trouble pulling images from Firebase into my Vue application

Currently, I am experimenting with a Vue application that requires users to upload an image to Firebase. After the image is successfully uploaded, it should be displayed within an img tag in the template. The issue I am encountering is retrieving the uplo ...

iPad not compatible with playing Mp4 videos offline

Having an issue with embedding an mp4 file on a webpage in iOS Safari. The video is embedded using the video tag: <video src='gizmo.mp4' width=560 height=320></video> However, instead of playing the video, the page shows the 'v ...

Isn't AJAX all about the same origin policy?

Despite my confusion surrounding the same domain origin policy and jQuery AJAX, I have noticed that when I make a GET request to a URL using jQuery, I am able to successfully retrieve the results. This goes against what I understood about the restriction ...

`Is it possible to animate the rotation of an image within an input control?`

After coming across this helpful answer, I successfully added a rotating GIF image as an icon inside an INPUT control on its right side. Simply applying the "busy" class to my control did the trick, and now it looks like it's in progress. input.busy { ...

Troubleshooting: Issues with JQuery and setTimeout() functionality

While using JQuery to monitor key presses for an HTML game, I encountered an issue where adding the jquery code to my gameloop resulted in an error message stating that keydown was not defined. <html> <head> //...Included JS files ...

When utilizing array.push() with ng-repeat, it appears that separate scopes are not generated for each item

I'm currently working on an Angular View that includes the following code snippet: <div ng-repeat="item in items track by $index"> <input ng-model="item.name"/> </div> Within the controller, I utilize a service to retrieve a Js ...

Create a variety of documents and bundle them into a zip file for easy

I'm currently implementing docx.js in my react application running on AWS Amplify (using a node backend). I am creating multiple documents and saving them individually by utilizing the packer to produce the document as a blob, then using the FileSaver ...

Guide on displaying a pop-up window upon changing the selected option in a drop-down menu

I am looking to create a popup window that appears when a certain value is selected from a drop-down list. However, I am unsure of how to approach this task and would appreciate a simple example to help guide me. I plan on using panel for the pop up. ...

The droplist functionality in jQuery does not seem to be functioning properly within an ASP.NET MVC 5

After adding an external theme to my project and writing a script for listing data in a dropdown list on a separate page, I encountered an issue where the script works on other pages but not on the Layout theme page. HomeController Note: The partial view ...