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

Steps to eliminate a specific value from an array

I need to remove values with the .html extension from an array in JavaScript, leaving only those items that do not have the .html extension. Here's my current code: main.js: var arr=["test1.html","power.html","main.html","save.md","kart.html","taste ...

The onclick event seems to be malfunctioning on the website

My goal is to implement a modal box that appears when a user clicks a button and closes when the user interacts with a close button within the modal box. I have created two functions for this purpose: check() : This function changes the CSS of an element ...

jQuery encountering error when uploading multiple files upon loading

I'm having trouble with this jQuery plugin ( ). Whenever I try to set the events on it, I keep getting an error message saying "Function expected". Can someone provide assistance? Everything seems to be working fine except for binding to the events. ...

manipulating the href attribute using jquery

I am facing a situation where I have an image with the unique ID of 27. My challenge now is to change the href attribute of the link that envelops it, utilizing jquery. Can you guide me on how to achieve this task? Below is the content of my link and ima ...

Gliding over the problem with the Azure line

Is there a way to hide the opacity and font on hover? I have tried using outline: 0; in my CSS but there is still a blue line lingering. Any ideas on how to remove it? If you need to see the code and the issue I'm describing, here it is: p { font ...

No matter how tall I make it, the scroll bar just won't stop showing

Check out this fiddle for more information: http://jsfiddle.net/LAueQ/ Even after increasing the height of the campaignDiv div, the scrollbar keeps showing up. If possible, I would like to avoid using overflow: hidden. ...

Has the zip creation tool in the Google Doodle on April 24th been coded entirely in JavaScript?

Was the Gideon Sundback Google doodle created using JavaScript? I attempted to follow along in Firebug, but I couldn't quite grasp its implementation details. Any ideas on how it was possibly implemented? Any insights on the potential techniques use ...

Steps to manage the time delay between mousewheel events triggering

Currently, I am working on a website for a movie production company that showcases their various films in full-screen mode. Each video is listed and there is a function that automatically takes the user to the next video when a mousewheel event occurs. How ...

What could be causing my HTML elements to shift position based on varying screen sizes or zoom levels?

Does anyone else experience their HTML and CSS elements shifting around based on the screen size or zoom level? I have screenshots illustrating this issue. Here is how it currently appears And here is how it's supposed to look ...

Comparing attribute selectors to class selectors in the realm of styling

I often come across code that looks like this: <input type="text" class="class1" name="text"> <input type="submit" class="class2" name="submit"> which is then styled as follows: input[type=text] { styles here...} input[type=submit] { sty ...

Efficiently loading Google Visualizations for core charts by utilizing AJAX within jQueryUI tabs

Loading Google Visualizations via AJAX in jQueryUI tabs After encountering a similar issue, I discovered a solution provided in the link above that partially resolved my problem. I am trying to use Google Visualization core charts within jQueryUI tabs wit ...

Emphasizing the chosen element in a list using angular

After retrieving an array of items from the database, my list is constantly changing, causing the HTML display to update dynamically. However, I am struggling with highlighting only the selected item in the list, as the entire list gets highlighted upon se ...

What is the most effective way to toggle the visibility of these rows within a table?

Initially, my plan was to incorporate collapsible rows into my table. However, considering the spacing and margins, I realized that approach wouldn't work. After some thought, I concluded that all I really need is a way to hide and show information on ...

Fixing a menu hover appearance

I recently encountered a small issue with the menu on my website. When hovering over a menu item, a sub-menu should appear. However, there seems to be a slight misalignment where the submenu appears a few pixels below the actual menu item. Check out the w ...

JavaScript and HTML with Node.js

Exploring the world of HTML, running smoothly with a static IP address 192.168.56.152 using apache on the host computer. <!DOCTYPE html> <html > <head> <title>OnlinePage</title> <meta charset="utf-8"& ...

What methods can we use to transform Bootstrap rows and columns to resemble a table design?

Attempt number one did not work due to padding issues in the columns. Attempt number two also failed, leading me to believe I may be making a mistake somewhere. This is what I am aiming for: Can anyone provide some assistance? I would prefer avoiding mo ...

The CSS is functioning properly on the local server, however, it is not loading

Feeling a bit overwhelmed... I've been developing an app using nitrous.io and everything was working perfectly (CSS displayed, able to login to Steam and save entries in the database). Exciting stuff! However, when I deployed it to Heroku, things star ...

Tips on changing rows within tables using HTML code

I have a code snippet that pulls data from a database and displays it in a table format. However, I am facing an issue where courses with the same term number are being displayed on separate rows. Here is the current code: <html> <head> <ti ...

Chrome glitch: how to make radio buttons bigger

Hey there! I'm having a little trouble trying to increase the size of my radio button using this CSS code. It seems to work in Mozilla, but not in Chrome. .rdo { margin: 1em 1em 1em 0; transform: scale(1.3, 1.3); -moz-transform: scale(1.3, 1.3); -ms- ...

Access the Ajax response and store it in a JavaScript variable

I've successfully created a script that inserts data into an MySQL database using a modal and AJAX. However, I'm having trouble retrieving the response to complete an input field. Below is my current script: $.ajax({ url:"insertar_cl ...