Samir said:
I don't know if this is easy or not, I have no clue on how to start it.
I have Seven different states.
I will be having a form with 7 textboxes, and I will enter 7 different
states each time in the textbox.
When I click on the button, it would call a function
the function would output :
6 different combinations of 3 states. So I would have 1-6 and for each
would list three states I entered in the textboxes.
This sounds a bit like a class assignment to me, but I'm
avoiding starting my real work, so I'll bite:
The way to start it is to state the problem more precisely.
As I understand it, you're looking for a function that will
take as input the values of seven text fields, and will
generate six different combinations of those seven values
taken three at a time.
1. It's not clear how you want these combinations to be
presented on your page.
2. Since there are 35 possible combinations of 7 items
taken 3 at a time, it's not clear whether you want to
choose six of them at random, or if it's ok to use the
same pattern each time.
If it doesn't need to be random, here's a trivial solution in
which combination #n contains the three sequential inputs
beginning with input #n (looping back to the beginning at the
end of the list of inputs.
So if the "states" are "alpha" "beta" "gamma" "delta" ..., the
first combination will be "alpha beta gamma", the second will
be "beta gamma delta", etc:
<html>
<head>
<title>Combinations</title>
<script type="text/javascript">
function combine(inArray,outArray){
for(i=0;i<6;i++){
outArray[i].value="";
var j=i;
for(k=0;k<3;k++){
outArray[i].value+=inArray[j++].value+" ";
j%=6;
}
}
}
</script>
</head>
<body>
<form>
<input name="state" value="a" size="4">
<input name="state" value="b" size="4">
<input name="state" value="c" size="4">
<input name="state" value="d" size="4">
<input name="state" value="e" size="4">
<input name="state" value="f" size="4">
<input name="state" value="g" size="4">
<br>
<input type="button"
value="combine"
onclick="combine(this.form.state,this.form.com)">
<hr>
<input name="com" size="8"><input name="com" size="8">
<input name="com" size="8"><input name="com" size="8">
<input name="com" size="8"><input name="com" size="8">
</form>
</body>
</html>