Randomizer javascript menu
Here's a fairly simple javascript menu that randomizes the contents of the list on "refresh" of the browser. There are two pieces: an external randomizer.js script and an HTML page that calls to it.
here's the javascript:
/* list all items */
var a_items = [
'question1',
'question2',
'question3',
'question4',
'question5',
'question6',
'question7',
'question8',
'question9',
'question10'
];
function randomize (a_items, n_count) {
var n_index, s_html = '<table cellpadding="4" cellspacing="1" border="0"><tr>';
while (a_items.length && n_count) {
n_index = Math.ceil(Math.random() * a_items.length) - 1;
s_html += '<td>' + a_items[n_index] + '</td>';
a_items[n_index] = a_items[a_items.length - 1];
a_items.length = a_items.length - 1;
n_count--;
}
return s_html + '</tr></table>';
}
// call randomizer
// param 1 - list of items
// param 2 - number of items to display
document.write(randomize (a_items, 10));
<html>
<body>
<script language="javascript" src="randomize.js"></script>
</body>
</html>
John Alex,
<a href="http://www.standmixer-reviews.com">Stand Mixer Reviews</a>