Switching destination links

As I dive into the world of programming, there's a specific concept that continues to elude me.

In creating a website, I've implemented a button that randomly redirects users to different destinations. However, my goal now is to alternate between two specific destinations - directing one user to page one and the next to page two.

Below is the current script handling the randomization:

<script>
   var randomlinks=new Array()

   randomlinks[0]="juice.html"
   randomlinks[1]="no-juice.html"

   function randomlink(){
   window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
   }
</script>

To trigger this script, I've incorporated the following form element:

<form method="post">
   <p><input class = "button button1" type="button" name="B1" value="Start Test >>" onclick="randomlink()"></p>
</form>

If anyone could offer some guidance on achieving my desired outcome, it would be greatly appreciated! Thank you in advance (:

Answer №1

When working on the client-side exclusively, it becomes challenging to share code between two distinct clients. For instance, clients A and B cannot be compelled to navigate back and forth between your provided links.

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

Modify the second dropdown list using Jquery when the first dropdown list changes

I have encountered an issue with using two dropdown lists. Specifically, I am trying to implement a feature where if the user selects the option "2" in the first dropdown list, a script should be executed. Here is the script: $('select[name="servic ...

Take the attention away from the canvas

Is there a way to shift focus away from the canvas and onto input fields in my HTML code? Right now, the canvas is holding onto focus even when I'm clicking on text inputs. This prevents me from typing anything into them. Ideally, I'd like for t ...

I am having trouble inputting information into a MySQL database as my current code is not functioning properly

Currently, I am working on a form and expanding my knowledge of MySQL. My goal is to insert only data into a MySQL Database. Below are the files I am using for this project. In my insert.php file, you will find the following code: <?php include_once( ...

Could anybody provide some assistance with JavaScript?

<div id="toggler" class="toggler"> <div id="toggler" class="line1"></div> <div id="toggler" class="line2"></div> <div id="toggler" class=& ...

Introducing a variety of sub-menu fonts within an elegantly designed jQuery vertical accordion menu

I am struggling to achieve different font sizes, colors, and weights for top and sub-menu level links in my simple jQuery vertical accordion. Despite changing the CSS, I can't seem to get it right. What am I missing? Is there an easy way to accomplish ...

How to vertically center text with button label in Bootstrap 4

I have a simple objective: I want to align a line of text to the left and a button to the right, with the text vertically aligned to the button's label. I've tried adjusting padding and margins without success. I feel like there must be an easy s ...

Converting a JSON file into an HTML table using PHP

I need help figuring out how to display JSON data in an HTML table. I have a script that successfully outputs my JSON content, but I'm struggling to format it into a table. Below is the code I have so far: <?php $dir = "/Apache24/htdocs/reservat ...

Viewing code on Ionic Serve is as quick as a blink of an eye

I am experiencing a strange issue where my code appears for just a moment after running ionic serve and then disappears. I have all the necessary components like nodejs, cordova, ionic, jdk, etc. installed on my machine. As a newcomer to ionic, I would rea ...

Displaying wordpress submenu CSS when both the parent and child are active

On my website, I am utilizing a WordPress menu in the sidebar. My goal is to have second level child items appear only when a parent menu item is clicked. You can view an example here: I managed to use some CSS code to ensure that the Function Space sub ...

The jQuery scripts are having trouble cooperating

Currently, I am in the process of developing a website. The main focus at the moment is on creating a responsive menu and incorporating jQuery scripts. However, I seem to be facing some challenges in getting everything to work seamlessly together. Each scr ...

Tips for positioning a canvas and a div element next to each other on a webpage

I have a canvas and a div element that I need to split in a 60% to 40% ratio. However, no matter what changes I make to the display settings, the div is always displayed before the canvas. The Div element contains buttons with color-changing properties fo ...

Canvas - Occasionally, using lineTo() can result in crisp edges in the drawing

I've created a simple Canvas drawing app. However, I've noticed that occasionally the lineTo() command generates a line with fewer coordinates, resulting in many edges: I'm currently using the latest version of Firefox - could this issue be ...

Ways to center items in a row-oriented collection

When dealing with a horizontal list, the issue arises when the first element is larger than the others. This can lead to a layout that looks like this. Is there a way to vertically align the other elements without changing their size? I am aware of manual ...

Desktop users will not see the mobile navigation bar

I'm working on creating a sidebar navigation that stays fixed on desktop but collapses on mobile devices. The issue I'm facing is that once I toggle the navigation on mobile, it remains toggled and doesn't show up on desktop. Check out my co ...

What is the quickest way to select CSS elements?

Imagine having a popup element labeled as "popup" with two buttons inside, one positioned on the left and the other on the right side, both having the class "popupbutton". Which CSS rule would be the most optimal in this scenario? #popup a.popupbutton ...

Access the hyperlink contained within the table

Having trouble clicking a navigation link inside a table? I've tried: getElementByID getElementsByClassName getElementsByTagName but none seem to be working. When using the following code: Set tbls = HTMLDoc.getElementByID("tabToggleTable") it r ...

Extract certain text from an element using a straightforward script

Is there a way to simplify this JavaScript code for splitting specific text from an element? Here is an example of the HTML element: <div id="ReviewBox"> <span>(By:) Hello</span> <div id="ReviewBox"> <span>By: Goodbye</ ...

Tips for aligning a Twitter button and a regular button side by side on a horizontal

I have two buttons - one for Twitter and the other a normal submit button. I am struggling to align them horizontally on the same line. After experimenting with various combinations of margin settings for ".buttonLine", ".twitter-share-button", and "#newQ ...

Ensure that the dropdown <select> remains open even while filtering through options

I am currently working on implementing a mobile-friendly "filtered dropdown" design: https://i.sstatic.net/SYjQO.png Usually, a <select> control remains closed until the user clicks to open it. Is there a straightforward way to keep it always open ...

Tips for showcasing a string value across various lines within a paragraph using the <br> tag for line breaks

I'm struggling to show a string in a paragraph that includes tags to create new lines. Unfortunately, all I see is the br tags instead of the desired line breaks. Here is my TypeScript method. viewEmailMessage(messageId: number): void { c ...