Creating a dynamic form that efficiently captures user information and automatically redirects to the appropriate web page

Sorry for the unusual question, but it was the best way I could think of asking. I have come across websites with fill-in-the-blank lines where you can input your desired information and then get redirected to another page.

For example:

"What are you searching for? I am looking for ______________"

After filling in the blank, users are redirected to their desired page. However, I am looking to provide a few options for users to choose from before redirecting them to another page on my WordPress website.

I am new at this and trying to achieve that feature. Any help would be greatly appreciated!

Answer №1

Imagine this as a demonstration page you've created with a select option labeled as "dropdown"

HTML

<html>
<body>
    <p>What are you searching for? I am searching for 
        <select id = "dropdown" >
            <option value="zero" selected>Select an Option</option>
            <option value = "one">Duckduckgo</option>
            <option value = "two">Qwant</option>
            <option value = "three">Jamun Search</option>
        </select>
    </p>
</body>

//JavaScript
function displayDropdown(){
    var paraTag = document.getElementById('list');
    paraTag.style.display = "none";
    var chosen = document.getElementById('dropdown');
    chosen.style.display = "block";
}
function goToPage(){
    var selected = document.getElementById('dropdown');
    var selection = selected.options[selected.selectedIndex].value; 
    if(selection == "one"){
        window.location.href = "http://www.duckduckgo.com";
    }
    else if(selection == "two"){
        window.location.href = "http://www.qwant.com";
    }
    else if(selection == "three"){
        window.location.href = "http://www.jamunsearch.rf.gd";
    }
    else {
        alert("Please choose an option to proceed!")    
    }
}
/* CSS */
.dropdown {
    display: none;
}
<!--HTML-->
<html>
    <body>
        <p>What are you in search of? I am searching for</p> <p id="list" onclick="displayDropdown()">__________</p>
            <select id = "dropdown" class="dropdown" onchange="goToPage()">
                <option value = "zero" selected>Choose One</option>
                <option value = "one">Duckduckgo</option>
                <option value = "two">Qwant</option>
                <option value = "three">Jamun Search</option>
            </select>
        </p>
    </body>
</html>

Once the user taps on '_____', it will disappear and reveal the select dropdown to be chosen.

The function goToPage() triggers when a choice is made by the user, hiding the drop-down list (display:hidden). The script obtains the value of the picked option which can be zero, one, two, or three. It then verifies against the predefined values.

window.location.href("http://www.example.com")
will forward the user to Example.com. You may modify that URL to match your WordPress URLs. If no selection is made, the page will prompt the user to make a selection before proceeding.

If you prefer to verify the condition with the select name, check out this article Obtain the Select Option Value

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

Looking to adjust the title font size when exporting DataTable to Excel?

Would like to customize the title of an excel file exported from Datatable. I attempted to implement a solution found on a stackoverflow post, but it ended up applying the customization to the entire sheet. $("#datatable").DataTable({ ...

Vue.js encountered an error: Unexpected TypeError in promise. The function $set is not recognized

Currently, I am working on fetching comments from the Reddit API and attempting to update an array using $set in order to refresh the view. However, I encountered an error: Uncaught (in promise) TypeError: $set is not a function Virtual Machine Component ...

Is it considered acceptable to house a myriad of variables within the token object in NodeJS?

Currently working on implementing authentication with NodeJS, expressJS, mongodb and React Native. Is it acceptable to include multiple variables in the token object like shown in this example? const token = jwt.sign( { userId: user. ...

Pass information submitted through a JavaScript prompt to an expressjs endpoint

I'm currently facing a challenge in extracting the value from my prompt in order to modify a category using a JavaScript function. Typically, I would rely on a form to pass variables to the request.body, but that's not an option here. This is wh ...

How to align the last item in the bottom row using Flexbox styling

Is it possible to center the last element when resizing the window to a smaller resolution, even though the parent's justify-content parameter is set to space-between? I understand that using center or space-around would achieve the desired result, bu ...

Boxes that change and adapt to the user's input

Need guidance on a tricky problem! I am working on a form to input various cities that the user wants to visit. The form currently consists of one form box and a submit button. My goal is to allow the user to enter multiple cities by clicking an "Add 1 ...

Updating state before and after making an API request

I have implemented an asynchronous function with prevState in my code. The purpose of using prevState is twofold: 1) updating a deeply nested object and 2) sending data to an API based on the current state. Asynchronous programming is utilized for the API ...

Guide to modifying Button on fetch response in React Native

After receiving a response from the server, I need to adjust the button based on the friends_status field in the following response: { "responseHeader": { "type": "314", "status": "200", "message": "Successfully found the profile" }, "ne ...

Utilizing the map function to incorporate numerous elements into the state

I'm struggling with 2 buttons, Single Component and Multiple Component. Upon clicking Multiple Component, my expectation is for it to add 3 components, but instead, it only adds 1. import React, { useState, useEffect } from "react"; import ...

How can you fetch data from a PHP file using AJAX before performing a header redirect?

I am currently in the process of adding more dynamism to my website. I have developed a forum from scratch and now I am integrating JavaScript into it. All the PHP backend work is complete. My next goal is to enable user login without having to refresh the ...

Is there a way to display the button solely when the cursor is hovering over the color?

When I hover over a particular color, I want the button to show up. However, instead of displaying the button only for that color, it appears for all the colors of the product. Also, the placement of the button on the left side means that if I try to hover ...

Choosing dynamically created components:Making a choice among elements that are generated

Currently, I am working on a task that involves moving list items between two separate lists and then returning them back upon a click event trigger. Below is a snippet of the basic HTML structure: Unchosen: <br> <ul id="unchosen"></ul> ...

Ways of incorporating text in a parallelogram shape

Here is the HTML code with ID attributes applied to both divs: <div id="herotext"> <div id="banner"></div> <h1 id="maintitle">Hey, I'm Charlie</h1> <p>This websi ...

Tips for showcasing a lineup horizontally with HTML and CSS

I'm currently working on creating a menu using HTML. I've included my links in an unordered list (ul) as shown below. In my CSS, I added a display:inline; property to the links to make them appear side by side like a menu. However, for some reaso ...

Issue with displaying MP4 movies in Angular

I'm trying to display an mp4 video in Angular 9: <video controls (click)="toggleVideo()" preload="none" *ngIf="post.moviePath != null" #videoPlayer> <source [src]="getMovieSanitazePath(post.moviePath ...

``The Art of Handling REST API with Express and Mongoose

Running Express on my application, I have a delete route set up as shown below: router.route('/lists/:id') .delete(function(req, res){ Entry.remove({ _id: req.params.id }, function(err, list){ if(err) ...

Guide to comparing the contents of two text fields and highlighting the altered characters using ReactJS

Is there a way to compare the contents of two Material-UI textfields and identify the characters that have changed in both? I came across a similar question, but it was specifically for ReactJS rather than C# Windows Forms: How can you highlight the chara ...

Creating a single Vuetify expansion panel: A step-by-step guide

Is there a way to modify the Vuetify expansion panel so that only one panel can be open at a time? Currently, all panels can be closed which is causing issues. I would like the last opened panel to remain open. I also want to prevent closing the currently ...

"Discrepancy found in results between Node-Fetch POST and Firefox POST requests

I have encountered a challenge while trying to replicate a successful log-in process on a website using node-fetch after being able to do so with Firefox. The login process consists of three stages: Visiting /login which returns a sessionToken from the we ...

How to dynamically insert a key into an array by locating a specific value in AngularJS

I need help adding a new key to a JSON array by searching for a specific key value. For example JSON:- [ { "$id": "2025", "ID": 41, "Name": "APPLE" }, { "$id": "2026", "ID": 45, "Name": "MANGO" }, { "$id": "2027", ...