1. Checkboxes

I have a form with many checkbox fields (lotto table), and I want to make a button to pick some numbers randomly. I have a script for generating numbers, but I do not know how to make corresponding checkboxes in the form checked according to the generated numbers.
I would appreciate your suggestions. Thank you.

Below is my script for generating numbers:

<script language="javascript">
<!--

var loop; //loop counter
var randy; //holds random numbers

function make_array(size) //creates a one-dimensional array
{
this.length = size;
for (a=0; a<size; a++) this[a]="";
}

function generatenos() //flags certain numbers in a one-dimensional array
{
hold = new make_array(document.lottery.max_number.value);

document.lottery.numbers.value = ""; //clear numbers box

//now we need to generate some numbers-----------------------------------------------

for(loop=0;loop<document.lottery.balls_drawn.value;loop++) //1 step through loop for each ball to be drawn
{
randy = Math.round(Math.random()*(document.lottery.max_number.value-1));
randy++; //ie. number between 0+1 (=1) and max_value-1+1 (=max_value)

if(hold[randy]==1)
{
loop--; //if number already chosen, go back one step in the loop
continue; //and start again (so no duplicate numbers)
}

if(hold[randy]!=1)
{
hold[randy]=1; //if not already flagged, then flag the number in the 'hold' list
}

}

2. Well, the best suggestion I can offer is to have your number generator spit out a number in a certain range, say 1 - 10 for sake of argument. THen assign your checkboxes names that are numbers 1 - 10. That way you can write a short Javascript to pattern match your generated numbers with your form names. Here is a skeleton of what should work:

Code:
```<html>
<script language="javascript">
function pairing() {
var num = generate(); // this is your random number genrator that you showed me.
var df = document.form1;
name = "check" + num; //ie. name = check1, check 2, etc.
df.name.selected = true;
}
</script>

<body>
</body>
<form name= "form1">
<input type= "checkbox" name = "check1">Option 1
<input type= "checkbox" name = "check2">Option 2
<input type= "checkbox" name = "check3">Option 3
<input type="Button" value = "go" onclick ="pairing();"
</form>
</html>```
Keep in mind, I haven't tested this code, but it should lead you on the right track. Post or pm if you still need help.

Drew

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•