How can you navigate to different pages in Chrome by selecting radio buttons that are designed as clickable

Currently, I am in the process of developing a website for my job and I have come across a dilemma with two radio button options. To make the text and radio buttons function as links that redirect users to specific pages within the website, I utilized <a> tags. Surprisingly, everything worked smoothly on Firefox. However, when I tested the website on Chrome, the text acted as a link but the radio buttons failed to respond. Clicking on them only resulted in the page refreshing without any action. In an attempt to fix this, I even added a submit button to direct users to the designated pages, but unfortunately, that did not resolve the issue. I tried to replicate the code from the website as closely as possible, and you can view it in the link below:

https://jsfiddle.net/hLph4at4/1/

<form name="frmSite" style="float: left; margin-top: 5px;"> 
  <a class="loginPg_choices" href="www.youtube.com">
    <input type="radio" name="site" value="1" id="radio_btn_1" style="float: left; clear: both;" />
    <span style="float: left; margin: -2px 0 0 5px;">Take me to youtube.</span>
    <br/> 
  </a>
  <a class="loginPg_choices" href="www.google.com">
    <input type="radio" name="site" value="1" id="radio_btn_1" style="float: left; clear: both;" />
    <span style="float: left; margin: -2px 0 0 5px;">Take me to google.</span>
    <br/> 
  </a>
  <a href="#" type="submit" value="Submit" title="Login" style="float: right; clear: both;">
    Submit
  </a>
</form>

Answer №1

If you want to trigger an action when clicking a certain element, you can simply add an onclick attribute to the tag, like this:

onclick="window.location.href = 'https://youtube.com'"

For a live example, you can check out this updated Fiddle: https://jsfiddle.net/hLph4at4/7/

This onclick event will always be executed, unless the propagation is explicitly stopped, even for radio buttons.

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

The CSS attribute selector is unable to target dynamically appended class names

Utilizing React's CSS animations add-on has been a seamless process, with everything running smoothly when using the provided classnames. .quote-enter { opacity: 0.01; transition: opacity .25s ease-in; } .quote-enter.quote-enter-active { opaci ...

The Slick carousel code downloaded from their official website is malfunctioning

I found this code on slick's website, but it's not working for me. Can anyone spot what I might be missing? http://codepen.io/anon/pen/pyEddO <html> <head> <title>My Awesome New Website</title> <link rel="styles ...

Tips for shifting a designated row upward in Chrome using JavaScript

Currently, I am working on a Javascript function that moves up a selected row. However, the issue I am facing is that when the row moves up, the old row is not being removed. For instance, if I move up the 'bbbb' row, it successfully moves up bu ...

AngularJS controller does not trigger ngRoute

I have developed a basic application to experiment with ngRoute functionality. The main page, index.html, contains a single link leading to a separate page named "informationdisplay.html". Despite configuring the route within the controller of the main pag ...

Stylish Pop-up Box appears hidden behind a different element

Is there a way to fix the issue of the FancyBox plugin being blocked by some part of the HTML on the page when trying to load a Vimeo movie into a popup? Here is the live link: click here : it's when you click on the slider image underneath the yello ...

Different ways to position two header tags on top of each other instead of next to each other

I am attempting to adjust the placement of my header tags so that the second header sits directly below the first one, rather than side by side. Currently, I am using h1 and h2 tags for my headers. I have experimented with placing both headers inside an h ...

Tips for executing a jQuery nested template in a recursive manner

Imagine a world where JSON objects and jQuery templating collide in a thought-provoking inception-like scenario. How can we dive deeper into this rabbit hole? The catch is, I'm a bit lazy and hoping the code will do most of the heavy lifting... Q:& ...

"Looking to spice up your website with a dynamic background-image

I've encountered a problem with my CSS code for the header's background image. Despite trying various methods to create a slideshow, nothing seems to be working. Can someone provide guidance? I have four banner images named banner1, banner2, bann ...

Is add1 missing from the DOM? Learn how to include it

Having an issue with Java-Script and an HTML form. The scenario is that there's a main form with an "Add" button, which when clicked should display a second form. Next to the second form is another button labeled "Add1," which ideally should trigger ...

Paper-dropdown-menu component failing to render properly in web browser

Encountering an issue with the rendered HTML for a basic paper-dropdown-menu. Instead of displaying as a styled menu, the list items are just appearing as a plain list on the page. Upon clicking the rendered paper-input component within the dropdown, the ...

Can someone please help me figure out why the "setInterval" function in my script isn't functioning as expected?

I've been experimenting with controlling the refresh rate of drawn objects in a canvas using JavaScript. Even after going through the tutorials and examples on w3.school, I'm still unsure why the "setInterval" function is not executing the "gener ...

Adjust images, documents, and videos to fit seamlessly within an iFrame

I am currently working on an MVC project with a View named Index.cshtml. Within this view, I have a dynamically created iFrame where the HTML content is generated in a string and then appended to a div using .html(). The content of the iFrame changes based ...

Guide to stacking blocks on top of each other

How can I create even spacing between blocks of different heights? For instance, in the image below, you can see that block 2 should be positioned directly under block 1. https://i.stack.imgur.com/RnYbP.png https://i.stack.imgur.com/LHvlz.png ...

Tips for choosing a sibling element on hover using CSS

I'm having trouble figuring out how to make the rect element change color to purple when the text is highlighted. Right now, only the text color is changing. Is there a way to achieve this using just CSS? The goal is for the rect to turn purple on ho ...

What is the best way in jQuery to display a particular div with a unique id when a link is clicked?

I have a div with the following structure: <article id="#pippo">blablabla</article> which I have hidden using jQuery $('article').hide(); Now, I want to create a link menu that displays a specific article id when it's clicked ...

Position the larger element in the center of the smaller container element

Is there a way to center an image without it covering up the paragraph below? Using position: absolute; or float: left; can lead to layout issues. <p>This is the first paragraph</p> <p><img src="http://placekitten.com/600/280"/>&l ...

What could be causing my right-floating elements to shift more towards the left with each occurrence?

After following a todo list tutorial, everything was running smoothly until I decided to add some styling to it. I placed a Font Awesome trash can icon inside a button with the class "remove." Essentially, I removed all the styles from the button, leaving ...

Is it possible to apply CSS based on a component's displayName?

Are you a CSS pro? I'm attempting to apply a class that will make all descendants of an element read-only, but for some reason the style isn't being applied as expected: #ComponentDisplayName * { -webkit-user-select: text; -moz-user-sel ...

What is the best way to incorporate buttons that trigger PHP scripts within a MySQL database?

I have a MySQL database filled with various records that I've displayed in an HTML table on a webpage. I want to add two buttons next to each record, both of which trigger PHP scripts. For example, let's say the table lists the names of three pe ...

Adjusting the size and dimensions of a wmv video embedded on a webpage

I am trying to embed a wmv file on my webpage. The issue I'm facing is that I can't adjust the video frame size to fit the object and div dimensions. Here's the code I'm using: <div style="width: 300px; height: 220px;"> ...