I am seeking assistance in troubleshooting this javascript code. Can someone please help me identify the issue?

function validateCredentials() {
    
    var username = document.forms["myForm"]["name"].value;
    var admin = "admin";
    var user = "user";
    var master = "master";
    
    if (username == "") {
      alert("PLEASE ENTER YOUR USERNAME and PASSWORD");
    }
    else if (username == user){
      window.location.href = "form1.html";
    }
    else if (username == admin) {
      window.location.href = "admin.html";
    }
    else if (username == master){
      window.location.href = "master-admin.html";
    }
    else{
      alert("Please provide a valid username");
    }
  }

Find the form code below: -

<form method="POST" id="myForm" name="myForm" action="">
    <input type="text" name="name" placeholder="Username" id="name" required/>
    <br />
    <input type="password" name="password" placeholder="Password" id="pass" required/>
    <br />
    <button type="submit" onclick="validateCredentials()">LOGIN</button><br />
    <button type="button">SIGN UP</button><br />
</form>

I am attempting to redirect to different pages based on different credentials, but encountering issues with the login process. Please help me identify the mistake I am making...

Answer №1

After running a test on your code, I found that the outcome was satisfactory. Could you confirm if form1.html, admin.html, and master-admin.html are all located in the same directory as the HTML file that contains the 'fun' function? I suspect there may be an error present. Please investigate further.

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

Recording the descending data points (excluding the dragged positions) from the bootstrap slider

I am struggling with the implementation of the BootStrap Slider from this source: I have encountered an unusual requirement. I need to capture the values of the slider only when the user stops dragging it, not during the process of sliding. In other words ...

Having trouble with webpack displaying CSS background images?

I've set up the html boilerplate using webpack. I'm currently encountering an issue where calling an image in my scss file like "background: url('/img/img.png');" isn't working. I've included the webpack file and folder struct ...

Can you explain the mechanics behind Angular Component CSS encapsulation?

Is it possible to avoid CSS conflicts when using multiple style sheets? Consider Style 1: .heading { color: green; } And Style 2: .heading { color: blue; } If these two styles are applied in different views and rendered on a layout as a Partial Vi ...

Having trouble with button alignment in the header with Bootstrap 3?

Using Bootstrap 3 and looking to adjust the alignment of a star icon with the title in my HTML page. Here is the current setup: <p class="pull-right visible-xs"> <h3><center>2000 Cadillac Eldorado Esc (Prospect heights) $3500 ...

Include the aria-labelledby attribute in the jQuery Datatable Pagination

Check out the HTML output created by the Jquery Datatable plug-in for pagination(https://datatables.net/plug-ins/pagination/full_numbers_no_ellipses): <div class="dataTables_paginate paging_full_numbers" id="my-table_paginate" aria-l ...

The height of the sidebar must be set to 100% in order to fully cover the

Take a look at the examples below. // Content removed .aside { position: relative; float: left; width: 195px; top: 0px; bottom: 0px; background-color: #ebddca; height: 100%; } Currently, I'm still searching for the right ...

Navigating in Electron with Create React App

I recently completed a project using create-react-app and electron. Everything was running smoothly in the development environment. Check out this image of my dev environment However, once I built the project and attempted to run it with electron, all I ...

Setting character limits within textareas based on CSS classes in a dynamic manner

I'm looking to develop a JavaScript function that can set text limits for multiple textareas at once using a class, allowing for flexibility in case specific textareas need to be exempt. However, I'm facing issues with my debuggers - Visual Studi ...

Fulfill the promise once all map requests have been completed

Currently, my focus is on developing a bookmark page that retrieves bookmark results with the respective restaurant IDs. Once the response is mapped, I populate an array with objects. My objective is to ultimately resolve the entire array in order to mani ...

Getting to a nested key in a JSON object with JavaScript: a step-by-step guide

Currently, I'm working with a JSON file and need to extract the fileName tag for use. { "dataset": { "private": false, "stdyDscr": { "citation": { "titlStmt": { "titl": "Smoke test", "IDNo": ...

"Implementing a Texture as Material in Three.js: Step-by-Step Guide

I recently discovered Three.js and I'm really enjoying it. As a newcomer to JavaScript, I'm eager to delve deeper into animation and related topics. //UPDATE I've been working on this code snippet, but unfortunately, it's not functioni ...

What's up with this unconventional jQuery formatting? Can someone shed some light on

I recently found a plugin that toggles checkboxes, but unfortunately it's not functioning correctly with the latest version of jQuery so I'm currently working on debugging it. Could someone please provide an explanation for the following code sn ...

AngularJS array not refreshing following an AJAX request

Currently, I am still in the process of familiarizing myself with Angularjs and actively learning about its functionalities. One issue I have encountered is that when I define an array and loop through it using "ng-repeat," the items within ng-repeat fail ...

The VARCHAR data type in MySQL does not support the inclusion of any alphabetic characters

I am currently working on setting up a MySQL database table and need to insert some values into it using PHP from a webpage. I have managed to achieve this, but I am running into an issue where I can only insert integer values into the table. I have tried ...

How can I retrieve the $index value of an ng-repeat element within a uib-dropdown?

I am currently working on implementing an ng-repeat loop that includes a dropdown menu for each element. I want the dropdown menu to contain functions that operate on the specific element, requiring access to the index of that element. Below is the code sn ...

Creating a user-friendly form in a Nuxt/Vue application that enables dynamic attribute creation

I am currently working on designing a form that enables users to create different variations for a product within a Nuxt/Vue application. The goal is to provide users with the ability to specify attributes for each variation using a text field. These attr ...

Prepare an email message for sending

Currently, I'm working on an app using officejs. My goal is to extract content from an Excel worksheet and insert it into an Outlook email. However, I don't want the email to be automatically sent by the system. Instead, I would like the new emai ...

Incorporate a style sheet for a colorful navigation bar

I'm looking to add a colored bar below my navigation menu but I'm unsure of the correct method to do so. What I need: EDIT: I also need guidance on how to position the navigation menu at 50% of the height of the logo. Currently, I have used a & ...

Guide to ensuring a jQuery modal box appears above other page elements

As I work on a jQuery popup modal box, I am faced with the issue of it pushing all other content aside when called. The toggleSlide() function is being used and works fine, but the layout problem remains. Attempts to rectify this by using position: relati ...

Techniques and Strategies for showcasing several images in close proximity

I am looking to arrange dummy images in a row next to each other, similar to the example shown here: https://i.sstatic.net/HUUGz.png Since my CSS skills are not very strong, I am seeking guidance on the proper way to achieve this. The images I have are a ...