Hi, having a major problem with a shuffle function....when shuffle is called, the numbers come back with commas and the array runs out of the div. I can't figure out how to add a space between the numbers.
What I would like is to have each index location in the array be put inside a separate div and locate all of those divs within one div (id-"numberbox"). So I would end up with 1 through n, each in it's own div and they would shuffle when the shuffle button is clicked. It kind of works a little bit sort of. Here's what I've got so far.....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var nums = []
function display_array() {
n = document.getElementById('input').value ;
for (var i = 1; i <= n; i++) {
document.getElementById('numberbox').innerHTML +=(nums.push(i)+" ");
}
}
function shuffle() {
document.getElementById('numberbox').innerHTML =" ";{
shuffle = function(o){ //v1.0
for(var j, x, i = o.length; i; j = parseInt(Math.random() * n), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
newArray = shuffle(nums);
document.getElementById('numberbox').innerHTML +=newArray;
}
}
function reset_counter() {
document.getElementById('numberbox').innerHTML = '';
document.getElementById('input').value = '';
document.getElementById('input').focus();
nums.length = 0;
}
window.onload = function() {
document.getElementById("input").focus();
}
</script>
</head>
<body style="height:100px;width:100%;background-color:#000000;color:#ffffff;font-weight:bold;">
<div id="header" style="height:100px;width:100%;">
<center>
<h1>Numbermer Guess</h1>
<input type="text" size="2" style="border: 6px solid #C0C0C0; text-align: center; font-size: 18PX; font-family: impact, times new roman; color: #B0C4DE; background-color: #190033; " id="input">
<input type="button" class="buttons" style="color: #B0C4DE; font-weight: bold; border: 6px solid #C0C0C0; background-color: #190033;" onclick="display_array()" size="2" value="GO">
<input type="button" style="color: #B0C4DE; font-weight: bold; border: 6px solid #C0C0C0; background-color: #190033;" onclick="shuffle()" size="15" value="SHUFFLE NUMBERS">
<input type="reset" style="color: #B0C4DE; font-weight: bold; border: 6px solid #C0C0C0; background-color: #190033;" onclick="reset_counter()" value="RESET">
</center>
</div>
<div id="left" style="width:20%;height:100%;float:left;">
</div>
<div id="content" style="float:left;width:60%; height:100%;">
<center>
<div id="numberbox" style="border:6px solid blue;font-size:40px;width:80%; height:100%;color:blue;text-align:center;padding-top:50px;">
</div>
</center>
</div>
<div id="right" style="width:20%;height:100%;float:right;">
<center>
<p>INSTRUCTIONS</p>
</center>
</div>
</body>
</html>
Anyone with any ideas would be appreciated. thanks.