Navigating to a specific page based on the selected option is the key to efficient web browsing

I'm currently working on a form development project and I'm looking for guidance on how to navigate to different pages based on the selection made in a radio button. Here's the current form setup with two radio buttons:

.sh_k .sh_sl {
    background-color: #edf7f8;
    color: #282828;
    font-size: 14px;
    margin-bottom: 20px;
    padding: 20px;
}

.sh_k .sh_sn {
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    -ms-flex-pack: justify;
    justify-content: space-between;
}

... (CSS code continues)

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
... (HTML and CSS code continues) 

I am aiming to achieve the following:

If the "Elaboration" option is selected, the form should redirect to elaboration.html. If "Revision" is selected, then the form should redirect to revision.html upon clicking the "Next" button.

I would greatly appreciate any guidance or assistance on how to implement this functionality in the form.

Answer №1

To implement this method, I suggest storing the URI in the radio button's value attribute and then accessing it using an event listener.

<!-- HTML -->
<form id="form">
    <div>
        <label for="dnaelaboracion">
            <div id="elaboracion-radio">
                <input name="dna" id="dnaelaboracion" type="radio" value="page1.html">
            </div>
            <span>Elaboration</span>
        </label>
    </div>
    <div>
        <label for="dnarevision">
            <div id="revision-radio">
                <input name="dna" id="dnarevision" type="radio" value="page2.html">
            </div>
            <span>Revision</span>
        </label>
    </div>
    <button id="submit" type="submit">Next</button>
</form>

<!-- JS -->
<script>
    const button = document.getElementById("submit");
    button.addEventListener("click", function(event) {
    event.preventDefault();
    window.location.href = document.querySelector('input[name="dna"]:checked').value;
});
</script>

If you prefer not to use the value attribute, you can also save the URI in a data attribute.

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

Integrating force refresh functionality into a React application

I currently have a React application running on an apache/PHP server. The React app is set to load on the home path by configuring PHP to load index.html at the / route, which then loads the React app. index.html // .... <div id="react-hook"></ ...

Retrieve information stored in a component's data variable

After creating a Vue repository using vue init webpack my-app My main.js file looks like this -- // The Vue build version to load with the import command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue fro ...

"Assure that setTimeout will be executed within the then method in

Within an Immediately Invoked Function Expression (IFFE), I am returning a Promise. The first thing that is logged is first, followed by third, and then second. Despite having the setTimeout inside the then block, shouldn't everything within it be exe ...

Error messages in HTML5 are notifications that are triggered when

My application features multiple tabs, each containing input fields that I want to validate on the client side. I am currently using HTML5 attributes like required and pattern to achieve this. When a required field in the first tab is left empty, the error ...

What is the best way to align the right column section below the left column section on a reduced screen size in a responsive design?

When the screen size is small, I want the "left-side" of my project to be displayed above the right side. The problem I'm facing is that as the screen shrinks, the left side starts getting hidden by the right side until it suddenly jumps to the right ...

Why am I unable to insert data into the 'sessions' database using connect-mongo?

I am utilizing connect-mongo in conjunction with express-session, and the session data is successfully being stored in Mongo. However, I want to enhance the sessions collection utilized by connect-mongo in order to include my own fields on top of it. I h ...

Issue encountered while trying to utilize the reset function of the FormGroup with the angular2-tinymce plugin

I utilized the FormGroup feature to construct my form, and I required a textarea component. I decided to use the angular2-tinymce library/package to create the form. Here is my HTML template: <form (submit)="submitCallLog($event)" [formGroup]="callLo ...

Equal-sized tiles in Highchart treemaps

I'm attempting to display JSON data in treemaps with equal squares. I discovered that the highchart-treemap library offers four built-in algorithms - squarified, slice and dice, stripes, and strip. However, none of these algorithms provide me with the ...

Unable to retrieve variable using the require statement

When attempting to access the variable 'app' from the required index.js in my test, I encounter difficulty resolving the 'app' variable. server.js 'use strict'; var supertestKoa = require('supertest-koa-agent'); ...

Ways to confirm the presence of strings within an array?

For instance: var array = ["apple", "banana", "cherry", "date", "elderberry", "fig"]; What is the best way to determine if "apple", "banana", and "cherry" are present in the array? I attempted using the indexOf() method but struggled to check for multip ...

Managing account activation errors in django: A step-by-step guide

Every time I attempt to click on an email activation link in order to activate a user account after submitting a registration form, I encounter an error message that says: The connection for this site is not secure; 127.0.0.1 sent an invalid response.. The ...

Incorporating Javascript into HTML

I have developed a script to randomly change the size of an element, but I am struggling to understand how to incorporate it using HTML or iframe code for randomization. <script type="text/javascript"> var banner1 = ["728", "90"]; var banne ...

Using jQuery to hide an element when the script is invoked

I'm encountering an issue where I create a file containing HTML and JavaScript that is loaded later via AJAX. One of the files should hide an element after it is loaded, but for some reason, it is not working. I have tried various methods to hide the ...

Issue: Attempting to write data after reaching the end in Node.js while using

I have encountered the following error: Heading Caught exception: Error: write after end at ServerResponse.OutgoingMessage.write (_http_outgoing.js:413:15) at ServerResponse.res.write (/home/projectfolder/node_modules/express/node_modules/connect/lib/mid ...

Retrieve information from the API prior to rendering the controller components

Hello there! I am looking to retrieve data from a factory before any of my controllers are loaded. After some research, I discovered that it can be achieved using the resolve function in AngularJS: angular.module('agent', ['ngRoute',&a ...

Tips for using the arrow keys to navigate the cursor/caret within an input field

I am trying to create a function that allows the cursor/caret to move inside an input field character by character using the arrow keys (ArrowLeft, ArrowRight) on a keydown event. Current Approach: const handleKeyDown = (e: KeyboardEvent<HTMLInputEle ...

How are these background images able to remain in a fixed position like this?

Trying to name this question correctly was a bit tricky. Hopefully I got it right. I have a new client and they want their website to have a similar feel to . If you check out the index page and scroll down, there's this cool 'smooth animation& ...

Warning message in React about missing floating prop in components

application.js (Webpack Entry Point) import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.jsx'; document.addEventListener('DOMContentLoaded', () => { ReactDOM.render(<App /> ...

Issue encountered with sortable table in list.js

Encountering a puzzling error while implementing list.js and tabletop for a sortable table sourced from a Google Doc. The error message reads: "Uncaught TypeError: Cannot read property 'childNodes' of undefined," pinpointing the first line in lis ...

What is the proper method for removing the object from the system?

Can you explain why there is an undefined value in the array and how to remove the object causing it? arr = [ {id:1,name:'aaa'}, {id:2,name:'bbb'}, {id:3,name:'ccc'} ]; for(var item in arr){ if(arr.hasOwnProperty(i ...