Randomly check a radio button after a certain time

300
November 23, 2016, at 1:44 PM

How do I randomly check a new radio button after a certain time?

I like to archive the effect that the checked radio button automaticially change every 5 seconds. Thank you!

<input type="radio" id="mc" name="radiobutton" value="Mastercard" checked>
<label for="mc"> Mastercard</label><br> 
<input type="radio" id="vi" name="radiobutton" value="Visa">
<label for="vi">  Visa</label><br> 
<input type="radio" id="ae" name="radiobutton" value="AmericanExpress">
<label for="ae"> American Express</label> 
Answer 1

You can use setInterval

var $inputs = $("input[type=radio]"); 
setInterval(function() { 
  var random = Math.floor(Math.random() * $inputs.length); 
  $inputs.each(function(i, node) { 
    node.checked = (i === random); 
  }); 
}, 5000); // 5000 = 5 seconds
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<input type="radio" id="mc" name="radiobutton" value="Mastercard" checked> 
<label for="mc">Mastercard</label> 
<br> 
<input type="radio" id="vi" name="radiobutton" value="Visa"> 
<label for="vi">Visa</label> 
<br> 
<input type="radio" id="ae" name="radiobutton" value="AmericanExpress"> 
<label for="ae">American Express</label>

Rent Charter Buses Company
READ ALSO
Combining elements of 2 dimentional array

Combining elements of 2 dimentional array

I have an JavaScript array:.

336
Google Maps - Dynamically Generating Markers on Map [closed]

Google Maps - Dynamically Generating Markers on Map [closed]

I"m new to google maps and am trying to get all the locations that are returned on my search page to appears on the corresponding map but I can't make it work. I have each listing display their longitude and latitude with the listing and I'm using the code below....

293
Using jQuery to toggle menu visibility

Using jQuery to toggle menu visibility

I have a code for a navigation page I'm working on, to be used on the tumblr platform. The navigation is basically set up like so, with #navstart being the category of the navigation items and #navitem used for individual items.

398
Can the JS Prepend statement edit pre-defined html?

Can the JS Prepend statement edit pre-defined html?

I define my html by setting it equal to a variable i am echoing, just for the sake of keeping my php page dynamic, however i am trying to append another input div onto my text area once a button is clicked via a javascript statement. In terms of syntax...

320