[thelist] JavaScript Help Needed

Rich Points rich at richpoints.com
Tue Aug 3 09:43:46 CDT 2004


Hi,
I'm setting up a PayPal account for a client and I'm trying to use a JavaScript to handle a price range.

The range is 
1-9 =      $2.00 each
10-50 = $1.00 each

I found this script from PayPal but I can't get it to do what I want.  

<script type="text/JavaScript">
<!-- Hide JS source from HTML validators
function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) { // process un-named selects
var i,amt,des,obj,pos,val;
  amt = obj1.baseamt.value*2.00;       // base amount
  des = obj1.basedes.value;           // base description
  for (i=0; i<obj1.length; i++) {     // run entire form
    obj = obj1.elements[i];           // a form element
    if (obj.type == "select-one" &&   // just get selects
        obj.name == "") {             // must be un-named
      pos = obj.selectedIndex;        // which option selected
      val = obj.options[pos].value;   // selected value
      pos  = val.indexOf ("@");       // price set?
      if (pos <= 9) amt = val.substring (pos + 1)*2.0;
      pos  = val.indexOf ("+");       // price increment?
      if (pos >= 10) amt = amt + val.substring (pos + 2)*0.5;
      pos  = val.indexOf ("%");       // percent change?
      if (pos >= 0) amt = amt + (amt * val.substring (pos + 1)/100.0);
      if (des.length == 0) des = val;
      else des = des + ", " + val;    // accumulate value
    }
  }
  obj1.item_name.value = des;
  obj1.amount.value = Dollar (amt);
  if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}
//-->
</script>

this is the page I'm running it from http://amiba.net/merchandise2.html

Thanks

--
Rich Points
Rich at RichPoints.com
http://RichPoints.com


More information about the thelist mailing list