1- // scripts.js — Global utilities for Annapurna
2- // All selectors are null-checked so this file is safe to include on any page.
1+ // scripts.js — safe global script with null guards
32
4- // ── Smooth active nav link highlight ──
5- ( function ( ) {
6- const links = document . querySelectorAll ( 'header nav a' ) ;
7- const currentPath = window . location . pathname . split ( '/' ) . pop ( ) ;
8- links . forEach ( link => {
9- const linkPath = link . getAttribute ( 'href' ) ;
10- if ( linkPath && linkPath === currentPath ) {
11- link . classList . add ( 'active' ) ;
12- }
3+ // Login form (only runs on login-registration.html)
4+ const loginForm = document . getElementById ( 'login-form' ) ;
5+ if ( loginForm ) {
6+ loginForm . addEventListener ( 'submit' , function ( event ) {
7+ event . preventDefault ( ) ;
8+ const email = document . getElementById ( 'login-email' ) . value ;
9+ const password = document . getElementById ( 'login-password' ) . value ;
10+ alert ( `Login attempt with Email: ${ email } ` ) ;
1311 } ) ;
14- } ) ( ) ;
12+ }
13+
14+ // Registration form (only runs on login-registration.html)
15+ const registerForm = document . getElementById ( 'register-form' ) ;
16+ if ( registerForm ) {
17+ registerForm . addEventListener ( 'submit' , function ( event ) {
18+ event . preventDefault ( ) ;
19+ const email = document . getElementById ( 'register-email' ) . value ;
20+ const password = document . getElementById ( 'register-password' ) . value ;
21+ const userType = document . getElementById ( 'user-type' ) . value ;
22+ alert ( `Registration attempt with Email: ${ email } as ${ userType } ` ) ;
23+ } ) ;
24+ }
25+
26+ // Track order form (only runs on order-tracking.html)
27+ const trackForm = document . querySelector ( '.track-form' ) ;
28+ if ( trackForm ) {
29+ trackForm . addEventListener ( 'submit' , function ( e ) {
30+ e . preventDefault ( ) ;
31+ const orderId = document . getElementById ( 'order-id' ) . value ;
32+ const displayId = document . getElementById ( 'display-order-id' ) ;
33+ const orderStatus = document . getElementById ( 'order-status' ) ;
34+ if ( displayId ) displayId . innerText = orderId ;
35+ if ( orderStatus ) orderStatus . innerText = 'In Transit' ;
36+ } ) ;
37+ }
0 commit comments