RE: Form validation problem. (COMPLETED)
by "Charlton, Mark" <Mark.Charlton(at)saint-gobain.com>
|
| Date: |
Fri, 27 Apr 2001 08:29:59 -0400 |
| To: |
"'Mike Taylor'" <lonewolf(at)one.net>, hwg-languages(at)hwg.org |
| |
todo: View
Thread,
Original
|
|
That would work, and you would have the ranks stored in your DB. The only
issue with this is that you cannot guarantee that the don't select, for
example, RED as ranks 1,2,3,4 & 5, so you might want to put something in the
test for that. It won't let them have 2 rank 1's though, so you either have
it one way or another, exclusively via the form's inherent restrictions.
I use javascript in similar exclusive situations to reset the other choices
if they conflict. EG
function resetButtons(strControl, strRank, strValue) {
var i;
strValue = eval('document.form1.' + strControl + ' Rank ' + strRank +
'.value');
// Test each other option for the same value and if it is the same, clear
that group
// Alternatively have a control group at the start of the
for (i=1;i<6;i++) {
if (i == strRank) {
// SKIP IT
} else {
if(eval('document.form1.' + strControl + ' Rank ' + i + '.value') ==
strValue) {
eval('document.form1.' + strControl + ' Rank ' + i + '.value') =
'';
}
}
}
Then <.input type=radio name='Q1 Rank 1' value=red
onChange="resetButtons('Q1','1','RED')">
I haven't tested that code, so it may be a little off in a few places. My
radio button handling is a little rusty, sorry :) I am sure someone will
correct me if it doesn't work.
With any form I would suggest server-side validation regardles of the
safeguards and client scripting you have in place, as it is all to easy for
someone to have a funny browser or something that ignores the client side
info that could skew your data.
Regards
Mark
-----Original Message-----
From: Mike Taylor [mailto:lonewolf(at)one.net]
Sent: Friday, April 27, 2001 12:35 AM
To: Charlton, Mark; hwg-languages(at)hwg.org
Subject: Re: Form validation problem. (COMPLETED)
Gotcha. So I should really rename my database columns to reflect the rank
number, not the value if I want this to work.
For example, right now in my SQL database table that houses this
information, I named the columns, "RED," "GREEN" and "BLUE" and then my plan
was to insert into each column the rank value. But by your approach I
should really reverse this, naming the columns "rank1, rank2, etc."
This way, I'd eliminate any need for client-side validation, because the
forms would do it by virtue of the like-named radio buttons.
Thanks for the help!
Mike
----- Original Message -----
From: "Charlton, Mark" <Mark.Charlton(at)saint-gobain.com>
To: "'Mike Taylor'" <lonewolf(at)one.net>; <hwg-languages(at)hwg.org>
Sent: Thursday, April 26, 2001 9:16 PM
Subject: RE: Form validation problem. (COMPLETED)
> I would suggest that you have 5 radio button groups. GRoup 1, group 2,
...
> group 5.
>
> Set up like this:
>
> <.h1>Q1) Best colour for tomato soup<./h1>
>
> RED
> <.input type=radio name='Q1 Rank 1' value=red>
> <.input type=radio name='Q1 Rank 2' value=red>
> <.input type=radio name='Q1 Rank 3' value=red>
> <.input type=radio name='Q1 Rank 4' value=red>
> <.input type=radio name='Q1 Rank 5' value=red>
>
> GREEN
> <.input type=radio name='Q1 Rank 1' value=GREEN>
> <.input type=radio name='Q1 Rank 2' value=GREEN>
> <.input type=radio name='Q1 Rank 3' value=GREEN>
> <.input type=radio name='Q1 Rank 4' value=GREEN>
> <.input type=radio name='Q1 Rank 5' value=GREEN>
>
>
> BLUE
> <.input type=radio name='Q1 Rank 1' value=BLUE>
> <.input type=radio name='Q1 Rank 2' value=BLUE>
> <.input type=radio name='Q1 Rank 3' value=BLUE>
> <.input type=radio name='Q1 Rank 4' value=BLUE>
> <.input type=radio name='Q1 Rank 5' value=BLUE>
>
> That should force only one rank per question, but should return
>
> Q1 Rank 1 = BLUE
> Q1 Rank 2 = GREEN
> Q1 Rank 3 = RED
>
> HTH
> Mark
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.