In the fiddle:
Two random selections (one from each array) are given on clicking the Go button.
My question:
I would like to use checkboxes (or similar) to determine which value should be randomised and which should be 'saved'.
Example:
- Click Go
- '2' & '6' are given
- Tick a checkbox under '2' to 'save' the value
- Click Go again
- 2 remains, second value is now 4
HTML:
<input class="btn" type="button" id="btnSearch" value="Go" onclick="GetValue();" />
<p id="message1" >Random</p>
<p id="message2" >Random</p>
JS:
function GetValue()
{
var myarray1 = new Array("1","2","3");
var myarray2 = new Array("4","5","6");
var random1 = myarray1[Math.floor(Math.random() * myarray1.length)];
var random2 = myarray2[Math.floor(Math.random() * myarray2.length)];
document.getElementById("message1").innerHTML=random1;
document.getElementById("message2").innerHTML=random2;
}
The example is completely stripped back for simplicity; I would be using it on a larger scale.
Any help on this would be greatly appreciated! Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire