Form instance This is the strength of a form. There is a small problem here: because my server does not support it now, the form cannot be submitted. I would print out your input and then return a false so the form is not submitted.
The onSubmit code does two things: checks whether you have filled in the data in the four text boxes, and then connects all the elements and prints them in the text area below.
There are examples in the original article. If you need children's shoes, please move here. I won't move them here.
Detect text area
This code will detect whether the user has entered content in the text box. It will ignore check boxes and radio buttons, but will always remind the user to select the select box. Even if you select it, you will be reminded because its value is always null. So it's best to use this code when you just want to detect text segments.
function checkscript() {
for (i= 0;i<4;i ) {
box = document.example.elements[i]; ‘!’); , I want to check elements 0--3, so I set a variable i. You'll notice that I'm using a number instead of using a name. This is an example of numbers being better than names.
Copy code
The code is as follows:
for (i=0;i<4;i ) {
Then I create a variable box to access the current element. If I don't create it, I need to write document.example.elements[i] several times, but I'm too lazy to write it.
The code is as follows:
box = document.example.elements[i];
If the value of this text box is empty, then we need to do:
The code is as follows:
if (!box.value) {
First we use the name of the text box. If your naming is clearer, then the user will better understand which text box has the problem.
The code is as follows:
alert('You haven't filled in ' box.name '! ');
As an additional service, we put focus on the text box in question so that the user can fill it in immediately. Because all browsers support it, there is no need to detect it:
The code is as follows:
box.focus()
Then we return a false. The code stops running and the form doesn't submit. Wait for user input.
The code is as follows:
return false;
If all text boxes are Filled in, return true to indicate that everything is normal. The function stops and the form is submitted.
The code is as follows:
}
}