Guide individuals towards two distinct web addresses depending on the information provided

I am currently working on a website for my upcoming wedding, which consists of 2 separate events with different sets of information regarding when and where they will take place. I would like to create a system where users can input some kind of prompt, such as a password, and depending on their response, be directed to the appropriate event page. For example, if they click "guest information," they will be prompted to enter a password and based on that either be redirected to site.com/page1 or site.com/page2.

While I have some knowledge in front-end technologies like JavaScript and jQuery, I'm not well-versed in server-side scripts. Is there an easy way to achieve this functionality without too much involvement of complex back-end development? Any help or suggestions would be greatly appreciated! Thank you!

Answer №1

When it comes to web development best practices, it is highly recommended not to expose passwords on the client side. However, for websites with a private nature, this might be acceptable. It's important to note that the following code snippet does not utilize jQuery, but could easily incorporate it.

Below is an example of how you can achieve the desired functionality (although it has not been tested):

<html>
  <body>
    <form>
      <input id="passwordForNextPage" type="password">
      <button onclick="checkDestination();">Submit</button>
    </form>
    <script>
        function checkDestination() {
          if (document.getElementById("passwordForNextPage") == "password1") {
            window.location.href = "/nextpage1.html";
          } else if (document.getElementById("passwordForNextPage") == "password2") {
            window.location.href = "/nextpage2.html";
          } else {
            alert("Please retype the password!");
          }
    </script>
   </body>
 </html>

Answer №2

Create a new form that includes an input box. Once the form is submitted, validate the value entered in the field and set it as the destination for window.location.href.

Answer №3

While this method may not provide the highest level of security, it should suffice for your needs. You can implement the following code to create a simple password authentication system:

HTML:

Enter Password: <input type="password" id="pwd">
<input type="submit" id="submit" value="Submit">

JavaScript:

$('#submit').on('click', function(e) {
    e.preventDefault();
    var password = $('#pwd').val();
    if (password == 'pass1') {
        window.location.href = "http://www.google.com";
    } else if (password == 'pass2') {
        window.location.href = "http://www.bing.com";
    }
})

Answer №4

If you want to open a link in a new window, you can utilize the window.location.href property along with the window.open() method.

For example, you can use window.open(''); // This code snippet will launch the provided link in a new browser window.

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

Verifying the presence of a value among various documents and retrieving the document containing it

Imagine having a variety of recipes stored in a MongoDB collection: { "recipeName": "barbecued chicken", "author_id": "123" } { "recipeName": "grilled steak", "author_id": "123" } { "recipeName": "pork and beans", "author_id": "444" } { ...

Show the button only if the checkbox is selected

Can someone help me figure out how to show a button on the header bar once the checkbox is selected in a listview? Any assistance would be greatly appreciated. I have tried implementing this on my Codepen: `http://codepen.io/Hin/pen/KpGJZX` ...

Utilizing a function to populate an attribute using .attr() in d3

I utilize .attr to generate link paths in D3, as demonstrated in Lines 42 of the live demo: link.each(function (d){}) .attr('x1', function (d) { return d.source.x; }) .attr('y1', function (d) { return d.source.y; }) .a ...

Filter WordPress posts using Ajax on a specific page

I have successfully implemented a posts filter and pagination feature on my website. However, I am facing an issue with the filter when it comes to filtering posts only on the current page. Currently, if I filter posts on page 1, the filter considers p ...

Location of the search bar

I am having trouble figuring out which class in Bootstrap I should modify in order to center the search bar in the navigation bar. Can anyone help? <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> ...

The directive stops functioning properly following the minification process

Here is a directive that I am working on: var tonicswitch = angular.module('tonicswitch', []).directive('multiSelectTonics', function(){ return { restrict: 'E', scope: { items: '=', ...

Media queries do not trigger the execution of CSS code

I am currently working on making a desktop-sized website responsive. However, I have encountered an issue where the CSS rule is being read by the browser but not executed, regardless of whether the media query rule is true or not. I have already included & ...

"Sorry, the getJSON function did not return any

I have attempted to execute a simple getJSON(), but it seems like I am not receiving any output. Shown below is my HTML/js: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Management ...

How can I customize index.html to display specific elements for different users?

My goal is to serve different users with a customized index.html page, where certain elements like buttons are only visible to specific users. I am utilizing the Express framework and familiar with registering views to control access to entire web pages ...

Encountered an unhandled exception: Unable to identify a GraphQL output type for the "anticipatedInvestmentSupportInfo"

I created a custom DTO named UploadedInvestmentDocumentInput and linked it to the expectedInvestmentSupportInfo property, but an error is occurring: uncaughtException: Cannot determine a GraphQL output type for the "expectedInvestmentSupportInfo" ...

JavaScript Event Listener not Working Properly

I've been attempting to implement a feature on my website where the header hides when scrolling down and re-appears when scrolling up. However, I'm struggling to make use of the code snippet below to achieve this functionality. Despite my thoroug ...

Perform calculations using the provided input values or null values in Javascript/Jquery

I'm a beginner in Javascript and JQuery. Take a look at my code that calculates an average (A) value based on three input values. https://i.sstatic.net/teGkc.png Check out the JQuery snippet below: $(".q-value, .e-value, .t-value").click(f ...

seize the cursor on chrome for windows

I'm experiencing an issue with two cursors appearing in Windows Chrome version 31.0.1650.57. The two cursors are grab and a default arrow. I have applied the following CSS: CSS div { width:200px; height:200px; background-color:maroon; ...

Altering the content of a span within a list item using AngularJS

Recently, I encountered some HTML code that looks like this... <ul id="sidemenu" class="wraplist wrapper-menu"> <li class="auto" ng-class='{"active": active == 1 }' ng-click="makeActive(1)"> <span class="arrow material-icons" ...

Ensure that any portion of a child DIV becomes visible only if it falls within the confines of the parent DIV, even if the overflow:hidden property is

My inner div can be resized by the user, and I have it inside another div. The issue is that when the inner div extends beyond the outer div, it covers it completely, or I have to use overflow:hidden, which hides the outer edges of the inner div. Ideally, ...

Optimal viewing experience with organized sections in full-screen layouts

There are numerous ways to make a div cover the entire screen with a full-screen image in the background. However, most of them involve using min-height:100% and background-size:cover properties. This can sometimes cause other sections like the footer or h ...

Is it recommended to apply a FLOAT attribute to DIV elements with a width of 100%?

Currently, I have a page with five stacked DIVs in a vertical layout. I am wondering if it is necessary to apply the FLOAT property to each DIV to adhere to good coding practices. It appears that there are no issues, such as re-wrapping, in any browser e ...

Removing a modal div element in React after navigating

import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import axios from "axios"; import Cookies from "js-cookie"; const LoginPage = () => { const [email, setEmail] = useState( ...

What is the best way to retrieve a JSON-formatted array through an AJAX call?

I am currently developing a system with two interconnected drop-down lists. The options in the second list (referred to as the 'sensor_list') are determined based on the selection made in the first list (known as the 'node_list'). To ac ...

Your program has encountered a crash and is currently on standby for any file modifications

=> MongoDB initialization in progress. W20210705-14:19:04.925(7)? (STDERR) /Users/alexio/.meteor/packages/promise/.0.11.2.cvynt8.js8ni++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/promise_serv ...