Hackforge Academy

Category: javascript

jquery form validation and effects

Published on 30 Sep 2026

Explanation

jQuery can be used to validate form fields before sending data to the server.

Code:

$('#loginForm').on('submit', function(event) {
    const username = $('#username').val();

    if (!username) {
        event.preventDefault();
        alert('Username is required');
    }
});

Explanation

Check the length of user input before allowing the form submission.

Code:

const password = $('#password').val();

if (password.length < 8) {
    alert('Password must contain at least 8 characters');
}

Explanation

jQuery provides show() and hide() methods for displaying and hiding elements.

Code:

$('#message').hide();
$('#message').show();

Explanation

fadeIn(), fadeOut(), slideUp(), and slideDown() provide simple visual effects.

Code:

$('#box').fadeOut(500);
$('#box').fadeIn(500);
$('#menu').slideUp();
$('#menu').slideDown();

Explanation

The toggle() method switches an element between visible and hidden states.

Code:

$('#btn').on('click', function() {
    $('#menu').toggle();
});

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community