[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phptest-users] Fwd: form validation
From: |
Brandon Tallent |
Subject: |
[Phptest-users] Fwd: form validation |
Date: |
Wed, 6 Nov 2002 14:37:08 -0800 (PST) |
I haven't tested this yet, but it looks nice for those
who are interested.
> From: "kathleen kihmm" <address@hidden>
> To: address@hidden
> Subject: form validation
> Date: Wed, 06 Nov 2002 12:15:38 -1000
>
> Here is the form validation javascript that I
> implemented.
> Thanks, for the great program.
>
> In test.php modify:
>
> echo "<form onSubmit=\"return validate(this);\"
> method=\"post\"
> name=\"test\" action=\"$PHP_SELF\">\n";
>
>
> // form validation function for PHPTest
> // by Kathleen Kihmm
> function validate(form)
> {
> var msg = "";
> var answered = "false";
> var q_num = 1;
> var name;
>
> // start the name equal to first element
> name = form.elements[0].name;
>
> // iterate through all elements except for
> // last two: submit and test_id elements
> for (var y = 0; y < form.length -2; y++) {
> // this loop interates through all the choices
> with the same name
> while(form.elements[y].name == name
> && form.elements[y].type == "radio"){
> if (form.elements[y].type == "radio"
> && form.elements[y].checked == true)
> answered = "true";
> y++;
> }
>
> if (answered == "false")
> msg = msg + "Question number " + q_num + " is
> blank.\n";
>
> // Reset answered to false
> // In the case where checked was true
> // set name to current iteration.
> answered = "false";
> name = form.elements[y].name;
>
> // decrement counter so the new element name
> // matches with the first occurance
> y = y-1;
>
> // increment question number
> q_num++;
> }
>
> // Alert the user if incomplete questions are
> present.
> // If there is no message return true--form is
> submitted.
> if (msg > "") {
> alert("The following questions(s) were
> incomplete:\n\n"
> + msg + "\n\n Please complete the
> questions and submit again.")
> return false;
> }
> else
> return true;
> }
>
>
>
>
>
_________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months
> FREE*
> http://join.msn.com/?page=features/junkmail
>
__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phptest-users] Fwd: form validation,
Brandon Tallent <=