F
Fabian H
Code:
<script tpye="text/javascript">
function in_array(a_mVal, a_aArray)
{
for (sIndex in a_aArray) {
if (a_aArray[sIndex] == a_mVal) {
return true;
}
}
return false;
}
function generateNumbers()
{
aUsed = new Array();
for (i=0; i<7; i++) {
do {
iRndNum = Math.round(Math.random() * 49) + 1;
} while (in_array(iRndNum, aUsed));
window.document.forms['LottoForm'].elements['num' + i].value = iRndNum;
aUsed[aUsed.length] = iRndNum;
}
}
function FocusField(a_iNum)
{
window.document.forms['LottoForm'].elements['num' + a_iNum].focus();
}
function checkNumbers()
{
aNums = new Array();
for (i=0; i<7; i++) {
iVal = parseInt(window.document.forms['LottoForm'].elements['num' + i].value);
if ((iVal <= 0) || (iVal >= 50) || isNaN(iVal)) {
FocusField(i);
window.alert('Bitte nur Zahlen von 1 bis 49 eingeben');
return false;
} else if (in_array(iVal, aNums)) {
FocusField(i);
window.alert('Bitte keine doppelten Zahlen eingeben');
return false;
}
aNums[aNums.length] = iVal;
}
return true;
}
</script>
<form name="LottoForm" action="lotto.php" method="post"
onsubmit="return checkNumbers();">
<input type="text" name="num0" style="width:30px;" />
<input type="text" name="num1" style="width:30px;" />
<input type="text" name="num2" style="width:30px;" />
<input type="text" name="num3" style="width:30px;" />
<input type="text" name="num4" style="width:30px;" />
<input type="text" name="num5" style="width:30px;" />
<input type="text" name="num6" style="width:30px;" />
<br />
<br />
<input type="submit" value=" Lottozahlen eintragen " />
</form>
<script type="text/javascript">
generateNumbers();
</script>
Tutorials.de.
Einen Link, um Dominik eine zu schreiben, findest du in seinem Profil.