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

What are the advantages of polymer's inter-component data binding?

I am working on a login component and I want to ensure that the login status is accessible by other components within my application. Is there anyone who can share some functional code snippets or examples? I require a method for binding or event handlin ...

What could be causing this highchart plot to fail to display in both IE and Chrome?

Check out the plot in this jsfiddle: http://jsfiddle.net/essennsee/y5HCm/ The plot looks good in Firefox, but only shows the legend in IE and Chrome. If I remove the following code snippet it works fine. Is there a different way to format the labels?: ...

Exploring an XML document with HTML

I have an XML file that is paired with an XSL file. The resulting output can be located here. I am working on creating an HTML webpage where users can input a search query, such as 'Year < 2009', into a search box. The table above will then d ...

Passing a JSON object from a Rails controller to Javascript

After creating a hash structure in Ruby like this: Track_list = {:track1=>{:url=>"https://open.spotify.com/track/2Oehrcv4Kov0SuIgWyQY9e", :name=>"Demons"}, :track2=>{:url=>"https://open.spotify.com/track/0z8yrlXSjnI29Rv30RssNI", :name=> ...

JQuery's attempt to disable the 'hover' feature fails to function as intended

I have a styled table where rows change background colors based on odd and even indexes, with a hover effect included. However, I want to disable the hover effect when a row is selected. Here's the current code snippet: .odd{ background: #f7f7f7 ...

Tips for rotating a responsive table on a mobile device's screen

I am currently managing a blogger website that features an HTML table on the homepage. I am struggling with making this table responsive for mobile devices, and I would like it to look similar to the image provided below. Can someone guide me on how to ach ...

Troubles arising while using ng serve in Angular 2

I'm currently facing an issue during the installation process of an existing Angular application. When trying to run the application using the ng serve command, I encounter the following error message: The "@angular/compiler-cli" package was not prope ...

Implementing an object as a filter in an NG-repeat function

I've created multiple select dropdowns that are populated from a JSON file containing categories. My goal is to use the selections made by users in the dropdowns to filter a list of apps generated using ng-repeat. In my Plunker example http://plnkr. ...

Connecting event listeners to offspring elements, the main element, and the entire document

My request is as follows: I have multiple boxes displayed on a webpage, each containing clickable divs and text. When a user clicks on a clickable div, an alert should appear confirming the click. Clicking on the text itself should not trigger any action. ...

Tips for displaying an edit icon on an individual row item when it is hovered

Attempting to create a functionality where hovering over a row in React triggers the appearance of an edit button/icon next to the folder name. The current approach involves assigning individual states to each row and utilizing a key to track them separate ...

Using jQuery to iterate over a multi-dimensional array and showing the child elements for each parent array

I am facing an issue with a multidimensional array that contains objects and other arrays. While it is simple to loop through the parent array and display its contents in HTML, I encounter a problem when there are multiple layers of arrays nested within ea ...

Troubleshooting Uploadify Issues

UPDATE: I discovered that the problem was related to Uploadify not having a session, which prevented it from accessing the designated page. To avoid this issue, simply direct it to a page without any admin login security ;) The issue stemmed from Upload ...

What is hindering me from fetching the information stored in my json file?

Currently, I am delving into learning AngularJS by working on a simple webpage for a company. This page will showcase products that are fetched from a json file. Following a tutorial from the AngularJS website, which covers the exact task I aim to achieve, ...

Display information from a specific identifier in a modal popup window after clicking a button using PHP and MySQL

When a button is clicked on my website, a popup window appears using modal functionality. The issue I am facing is not being able to retrieve the correct data based on the id of the button. Below is the HTML table code snippet: <tbody> <?php $cou ...

Troubleshooting lack of error responses from Backend RestAPI with Axios

I am currently facing an issue with receiving a response from my backend system (Node.js Express RestAPI). exports.send = function(req, res) { console.log("sent function running!") let contact = new Contact(req.body) contact.send() ...

When I try to scroll on my mobile device, the element is forced to reload

My donate page has a header with a generic placeholder image. On mobile devices like iPhones and Androids, the page initially looks great. However, when I scroll down and then back up, the header disappears for a moment before reappearing as originally ren ...

Extraction of Canonical URLs

I am completely new to VBA programming and I need assistance with extracting links related to specific keywords from a website. My goal is to have these sourced links as the final outcome for all keywords in my list using a VBA program. The code I've ...

VueJS: interactive input field with dynamic value binding using v-model

I am facing an issue with VueJS regarding setting the value of an input radio along with v-model. I am confused as to why I am unable to dynamically set a value to an input and use a model to retrieve the user's selection. Here is a clearer represent ...

Exploring web pages with JavaScript events

I am currently trying to compile a list of singles that were released in the year 2018 from allmusic.com. While accessing their advanced search page and setting the parameters is simple enough, the challenge lies in extracting the information manually. Th ...

Disabling the shadow when setting the face color in Three.js

When creating geometric objects in my project, I am randomly setting colors on the faces: // Material used to create the mesh var material = new THREE.MeshLambertMaterial({ color: 0xffffff, ambient: 0xffffff, vertexColors: THREE.FaceColors}) function ad ...