[thelist] testing for empty in javascript

.jeff jeff at members.evolt.org
Tue Jul 16 13:40:01 CDT 2002


jeremy,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Jeremy Weiss
>
> The page is at
> https://whatsmyhomevalue.com/membership_form.htm
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

the verisign logo at the bottom of this page is causing a non-secure
elements warning in ie.  either make the request for the image from verisign
via ssl (https) or move a copy of the image to your own site and make the
request via ssl there like the rest of your images.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> We 'selling' zip codes to real estate agents.  The
> reason I want to be able to remove one and have the
> total go down is b/c people tend to change their mind.
> An agent may want to purchase a several zip codes, but
> when they see the total price they may decide they
> don't want so many zip codes and thus they'll go back
> a remove a few of them.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

since all your zip code fields are named the same, they're accessible as an
array.  so, simply loop over that array of fields to get the total number of
fields with a value.  then, multiply the total number of fields by the price
per zip code and set your total amount due field to that value.

<script language="JavaScript" type="text/javascript">
<!--
  function DecimalFormat(number, places)
  {
    number = (Math.round(number * 100)) / 100;
    return (number == Math.floor(number)) ? number + '.00' : ((number * 10
== Math.floor(number * 10)) ? number + '0' : number);
  }

  var price_per_zip = 79.95;

  function ChangeTotal(oForm)
  {
   var zip_count = 0;
   for(i = 0; i < oForm.zip.length; i++)
   {
     if(oForm.zip[i].value)
       zip_count++;
   }
   oForm.amountdue.value = DecimalFormat(price_per_zip * zip_count, 2);
  }
// -->
</script>

additionally, make sure to pass a reference to the form object in your
ChangeTotal() function call in your onchange event handlers, like so:

onchange="ChangeTotal(this.form)"

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/





More information about the thelist mailing list