Notification (jQuery) failing to display user messages

Is there a way to retrieve the post title and display it in a notification? The notification's title is extracted from a form and shown in the notification. When the user clicks the submit button, the system captures the duration and title, displaying the notification for the specified time frame. Here's the code I've posted... any suggestions on improving it or providing an alternative solution?

$(document).ready(function() {
    $("#form").validate({
                rules: {
                    time: {
                          required: true,
                           number: true
                          },
                    title: "required"
                },
                messages: {
                    time: "Please enter time (in seconds)",
                    title: "Please enter the title"                
                }
            });
    
    

    $("#notify").hide();
    
    $("#form").submit(function(e) {
        if($('#form').valid()) {
            $("#notify").slideDown();

            var timeOut = parseInt($("#time").val())*1000 ; 
            var str = parseInt($("#title").val());

            setTimeout(function() {
                $("#notify").slideUp();
            }, timeOut, str);
        }

            return false;
        });

    
    });
    
#notify
{
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    height: 50px;
    background: #00FF00;
    opacity: 0.8;
    display: none;
}


#message
{
    width: 100%;
    text-align: center;
    padding-top: 15px;
}
#form .formelement
{
    display: inline-block;
    padding: 10px 10px;
    width: 900px;
}

#form .formelement label{
    float: left;
    text-align: left;
    width: 110px;
}

#form .submit {
    padding: 10px;
    width: 220px;
    height: 40px;
}

#form .formelement label.error {
    color: red;
    display: inline-block;
    margin: 4px 0 10px 100px;
    padding: 0;
    text-align: left;
    width: 900px;
}
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script src="valid.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />



<div id="notify">
    <div id="message"></div>
</div>

<fieldset>


<form action="" id="form" >

            <div class="formelement">
                <label for="time">Time (in Seconds): </label>
                <input type="text" name="time" id="time"/>
            </div>

            <div class="formelement">
                <label for="title">Title: </label>
                <input type="text" name="title" id="title"/>
            </div>
 
                    
            <div class="formelement">
                <input type="submit" value="Show Success" class="submit" id="s"/>
            </div>


</form> 
</fieldset>


</html>

Answer №1

There are a couple of issues with your code. Firstly, you have missed a closing parenthesis on the second-to-last line of your JavaScript.

Secondly, you have included jquery.min.js twice in your code. Since validate.js was attached to the first instance, the second one will not have access to the plugin. Remove the redundant loading of jquery.min.js.

$(document).ready(function() {
        $("#form").validate({
            rules: {
                time: "required",           
            },
            messages: {
                time: "Please enter Time in Miliseconds",                  
            }
        });

        $("#notify").hide();

        $("#form").submit(function(e) {
            $("#notify").slideDown();

            var timeOut = parseInt($("#time").val()); 

            setTimeout(function() {
                $("#notify").slideUp();
            }, timeOut);

            return false;
        });
    });
#notify
{
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    height: 50px;
    background: #FF0000;
    opacity: 0.8;
    display: none;
}


#message
{
    width: 100%;
    text-align: center;
    padding-top: 15px;
}
#form .formelement
{
    display: inline-block;
    padding: 10px 10px;
    width: 900px;
}

#form .formelement label{
    float: left;
    text-align: left;
    width: 110px;
}

#form .submit {
    padding: 10px;
    width: 220px;
    height: 40px;
}

#form .formelement label.error {
    color: red;
    display: inline-block;
    margin: 4px 0 10px 100px;
    padding: 0;
    text-align: left;
    width: 900px;
}
<body>


<div id="notify">
    <div id="message">SUCCESSFULL</div>
</div>

<fieldset>



<form action="" id="form" method="post" >

            <div class="formelement">
                <label for="time">Time (in Ms): </label>
                <input type="text" name="time" id="time"/>
            </div>

<div class="formelement">
                <input type="submit" value="Show Success" class="submit" />
            </div>



</form> 
</fieldset>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
</body>

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

The CSS selector within the website's URL

When a URL like www.example.com/#signup is entered, the browser focuses its view on the HTML element with the ID signup. Is this correct? Can the CSS style of the element be changed if it is focused in this way? For example, if there is a div element wit ...

Is it possible to vertically resize just one of three divs to match the size of the window?

I'm facing a challenge in creating a responsive webpage with multiple divs. Here is the structure I am trying to achieve: <div id="container"> maximum width of 1200 and height of 1000 <div id="vertically-static-top">20 pixels high< ...

PHP does not provide any error when an update on a database row fails

When I try to update values retrieved from the database into a form on submission, the process fails without any error message. Below is the PHP code snippet: <?php session_start(); $username=$_SESSION['uname']; $cn=mysqli_connect("loc ...

Storing JSON data as a string within JSON format with the help of PHP

When conducting testing, I am looking to utilize Ajax for requesting JSON data from the server. The JSON format that Ajax should receive appears as follows: json=[ {"source":"pa","jsonstring": '{"a":1,"b":2,"c":3}'}, {"source":"pa","json ...

Tips for creating gaps between wells within a Bootstrap row

Utilizing bootstrap, I am aiming to position two wells side by side without them being squeezed right next to each other. However, I am encountering some issues with achieving this. Here's the code snippet I am currently using: <div class="contai ...

Incorporating a hamburger symbol into an established menu for easy navigation

I have come across a tutorial on creating a navigation menu with a logo positioned to the left. However, I now wish to incorporate a hamburger icon for mobile devices and I am unsure about the process. Despite my efforts to find a suitable tutorial onlin ...

Is it possible to enable CSS margins to collapse across a fieldset boundary in any way?

One interesting CSS behavior is that adjacent vertical margins typically collapse into one another. In other words, the space between elements will be equal to the larger margin instead of the sum of both margins. Interestingly, fieldset elements do not f ...

Manage and modify data values

Currently, I am developing a weather forecast app and facing an issue with changing the temperature from Celsius to Fahrenheit upon hovering. Despite my attempts, the changes I make either do not reflect or completely erase the line. I am eager to learn ...

Display an HTML code snippet on the webpage

I'm facing a situation that has been discussed before on this platform. However, I want to present my problem in a different light. I am working with PHP and need to display an HTML string from the database on my webpage. The issue is that the CSS app ...

The JQuery(document).ready function does not seem to be executing on the webpage, but it works as expected when placed in a

I have encountered a peculiar problem. It's strange to me because I can't figure out the root cause of it, despite trying everything in the Chrome Developer Tools debugger. Here is a snippet of code that works when I run it from a file on my desk ...

Creating a variety of Flexslider slideshows on the fly

Check out this snippet of code: <?php foreach ($objVideos as $objVideo) : ?> jQuery('#carousel-<?php echo $objVideo->id; ?>').flexslider({ animation: "slide", controlNav: false, animationLoop: false, ...

The jQuery click event is failing on the second attempt

My PHP code dynamically generates a list, and I want to be able to delete rows by clicking on them. The code works fine the first time, but not the second time. HTML <li> <div class="pers-left-container"> <img src="<?php ech ...

What is the best way to ensure that my drop down select menu consistently displays the same data even after performing a query with the menu?

Hey there! I'm facing a little hiccup with a drop-down selection box. Here's what I'm trying to do - get someone to log into a database, and then display all available tables in the selection box. Once they choose a table, they hit select an ...

Dealing with JSON data in the format of `(Object object)` requires a specific approach

I originally encountered object object when attempting to display JSON API data in HTML. I then used keyvalue in *ngFor which allowed me to display the object, but I am wondering how I can access and display the entire JSON data? Here are the relevant cod ...

Creating an Eye-catching Presentation: Tips for Adding Text to Your CSS3 Slideshow

I am currently in the process of creating a CSS3 slideshow with text for each image. I found inspiration from this example: . However, I made some modifications to make it responsive. Here is the HTML code I have used: <div id="slideshow"> < ...

The callback function of the $.ajax statusCode method does not receive any parameters

As per the official jQuery documentation: If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error, they take the same parameters as the error callback. However, when I use th ...

Automating the movement of a slider input gradually throughout a specified duration

I am working on a website that includes a range input setup like this: <input type="range" min="1036000000000" max="1510462800000" value="0" class="slider" id ="slider"/> Additionally, I have integrated some D3 code for visualizations. You can view ...

Node replication including a drop-down menu

Is there a way to clone a dropdown menu and text box with their values, then append them to the next line when clicking a button? Check out my HTML code snippet: <div class="container"> <div class="mynode"> <span class=& ...

Employ a for loop to generate custom shapes within the canvas

EDIT: I will be sharing all of my code including the HTML and JS. Pardon me for the abundance of comments. I am attempting to generate rectangles in a canvas using a for loop (taking user input) and then access them in another function to perform certain ...

Is there a way to lead to a password-protected page without making it accessible through the URL?

I'm currently honing my skills in web development and embarking on a project to create an interactive puzzle website. The premise is simple - the homepage will feature just an answer input field where users can enter the correct solution to progress t ...