David,
Thanks for taking the time to help me out on this. In fact, I would very
much prefer to do the check client-side -- I've only steered clear of it
because of my lack of expertise with javascript. I am fiddling around with
the example you provided (thanks for taking the time to write that), and
came up with the following:
<script language="Javascript">
function validateForm(){
var registeredCount = #registered.registered_count#;
for (i=0;i<document.adminchange.length;i++){
if (left(document.adminchange.elements(i).name,
11="status_name")
if (document.adminchange.elements(i).value = "1")
registeredCount = registeredCount + 1; }
if (registeredCount > #classname.class_size#){
alert('The maximum class size is " & #classname.class_size# & ".");
return false; }
return true;}
</script>
</cfoutput>
(I named the form "adminchange".) I keep getting a javascript error
"unterminated string constant". I'm assuming that I need to change the
"element" placeholder? I know I'm sounding really ignorant here, but not
dealing with this every day, I need to lean on some expertise a bit more.
I'll be up all night tonight until I get this piece working. They want to
put this into production tomorrow morning!
Thanks so much for your help!
Terri
----Original Message Follows----
From: "Hayes, David" <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: CF-Talk <[EMAIL PROTECTED]>
Subject: RE: comparing original data with user inputted changes
Date: Mon, 25 Sep 2000 15:32:05 -0500
OK. Assuming that the submitted page contains ALL the requests for the
class, you don't really care what the current vs. original status is for
each item, right? You only care if the total "registered" GT "class size".
You could do something like,
(pseudo code)
get maxClassSize
set registeredCount = 0
LOOP formfields
IF formfield name is one you're interested in and value =
'registered'
increment registeredCount
ENDIF
ENDLOOP
IF registeredCount > maxClassSize
abort
ENDIF
UPDATE DB
Of course, the admin is going to be bummed out if you don't return the
selected values on the form for them to resubmit. In addition, your server
has to spend time processing invalid input. This seems like a good
opportunity for some client-side validation. When the user clicks the form
Submit button, you could loop through the appropriate form fields and get
the "registered" count; you could compare this to the maxClassSize, stored
in a hidden form field or a javascript variable . If the value is too high,
display an alert, and interrupt the processing.
I don't know what your experience is with JavaScript, but it's the same
psuedo-code as your CF page. One important piece of JavaScript knowledge is
that the form elements form a collection you can loop through. You also
need to give the relevant fields a similar prefix.
function validateForm(){
var registeredCount = 0;
for (i=0;i<document.formname.length;i++){
if (left(document.formname.elements(i).name, 11) =
"status_name")
if (document.formname.elements(i).value = "1")
registeredCount = registeredCount + 1;
}
if (registeredCount > maxClassSize){
alert('The maximum class size is " & maxClassSize & ".");
return false;
}
return true;
}
Of course, if you're using VBScript, the syntax is different. Good luck.
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.