Password Generator Tutorial
Page Three
Join the Discussion
form.num.checked = form.lower.checked = form.upper.checked = 1;
alert('You must allow some type of characters');
return;
}
if (!ffnc && !fflc && !ffuc) {
form.flower.checked = form.fupper.checked = 1;
alert('You must allow a start character');
return;
}
This code validates that at least one checkbox in each of the two groups is selected and produces an alert popup with an error message if either group is empty. Note that I can reference the short named fields that I copied the form fields to to test if they are all not checked but have to use the original names to actually update the form fields back to their original values. I assign 1 to the fields that I want checked rather than true because the two values are equivalent and 1 is shorter. I have also combined the assignment statements together to make the code shorter as well. In each case we end with a return statement since if the input is not valid we don't want to even try to generate a password.
form.len.value = 8;
alert('Please generate a password between 7 and 20
return;
}
Here I validate the length that has been entered. First I quickly test it for numeric and then test that the value is between 7 and 20. Because Javascript only looks at the code following an || (or) condition if the prior condition is true the tests for less than 7 and greater than 20 will only be performed if the value is numeric.

