In addition to Nate's solution you could also use the this keyword onblur to
do what you want, and you dont have to think about the names.

<script>
var total = 0;
function addVal(number) {
    //adds passed value to running total
    var total += number;
    //sets hidden field to current running value
    document.formname.total.value = number;
}
</script>

<input type="text" name="#dynamic#" onblur="addVal(this.value);">
<input type="hidden" name="total" value="0">

I just typed this up, so there might be a type somewhere. You would probably
also want to do check if the passed value is numeric before adding it too.

function isNumeric(string, ignoreWhiteSpace) {
 if (string.search) {
  if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) ||
(!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
 }
 return true;
}

jon
----- Original Message -----
From: "Angel Stewart" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, November 13, 2001 9:39 AM
Subject: Jscript totalling with dynamic CF Fields..


> Hello all,
>
> Umm..I'm in a bit of a bind.
> I have several rows of fields that are dynamically named like
> Reg_#CurrentDate# or VAC_#CurrentDate#.
>
> At the end of each row, I need a Total of the numbers entered into the
> fields to show dynamically, as the user enters values into each field.
>
> How in the nine hells am I going to do that? I will have to somehow pass
> the name of the field (which is dynamically generated) to some
> Javascript (or Vbscript it doesn't matter right now), and then do the
> calculation with the code attached to the onBlur() event of each field.
>
> But I have no idea where to even start with writing code like this.
>
> -Gel

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to