Reply
need help with javascript problem need exclent java programer
Old 06-20-2005, 05:49 AM need help with javascript problem need exclent java programer
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
hi i need help i got this bit of code that does excatly what i want it to do the problem i have is when you click add to cart it goes to paypal and you get a error messageing saying value must be more than zero im gussing somwhere in the script it not pikcing up the value and is asuming that the value is zero any help

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0
bgColor=#ffffff id=Table_02b>
<!--DWLayoutTable-->
<SCRIPT language=JavaScript>
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</SCRIPT>
<SCRIPT type=text/javascript>
<!--
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, tst) { // Read the user form
var i,j,amt,des,obj,pos,val,op1a="",op1b="",op2a="",op 2b="";
amt = obj1.baseamt.value*1.0; // base amount
des = obj1.basedes.value; // base description
if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
if (obj1.baseos0) op1b = obj1.baseos0.value;
if (obj1.baseon1) op2a = obj1.baseon1.value;
if (obj1.baseos1) op2b = obj1.baseos1.value;
for (i=0; i<obj1.length; i++) { // run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == "select-one" && // just 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 >= 0) amt = val.substring (pos + 1)*1.0;
pos = val.indexOf ("+"); // price increment?
if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
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
} else
if (obj.type == "checkbox" || // just get checkboxex
obj.type == "radio") { // and radios
if (obj.checked) {
val = obj.value; // the value of the selection
pos = val.indexOf ("@"); // price set?
if (pos >= 0) amt = val.substring (pos + 1)*1.0;
pos = val.indexOf ("+"); // price increment?
if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
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, or text
}
} else
if (obj.type == "select-multiple") { //one or more
for (j=0; j<obj.options.length; j++) { // run all options
if (obj.options[j].selected) {
val = obj.options[j].value; // selected value (default)
if (des.length = 0) des = amt;
else des = des + ", " + val;// accumulate value, or text
pos = val.indexOf ("+"); // price increment?
if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
}
}
} else
if ((obj.type == "text" || // just read text,
obj.type == "textarea") &&
obj.name != "tot" && // but not from here
obj.name != "qty") {
val = obj.value; // get the data
if (val == "" && tst) { // force an entry
alert ("Enter data for " + obj.name);
return false;
}
tag = obj.name.substring (obj.name.length-2); // get flag
if (tag == "1a") op1a = op1a + " " + val;
else if (tag == "1b") op1b = op1b + " " + val;
else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
else if (des.length == 0) des = val;
else des = des + ", " + val;
}
}
// Now summarize stuff we just processed, above
if (op1a.length > 0) obj1.on0.value = op1a;
if (op1b.length > 0) obj1.os0.value = op1b;
if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
obj1.item_name.value = obj1.qty.options[document.mfrm.qty.selectedIndex].value + " " + des;
obj1.amount.value = Dollar (amt*qty.options[document.mfrm.qty.selectedIndex].value);
}

var arrPrices = [1,8.3,2,8.6,20,14,40,20,60,26,80,32,100,38,200,68];


function updatePrice() {
total = document.mfrm.tot;
quantity = document.mfrm.qty.options[document.mfrm.qty.selectedIndex].value;

for (i=0;i<arrPrices.length;i+=2)
{
if (quantity == arrPrices[i])
{
i++;
price = arrPrices[i];
total.value = document.mfrm.pound.value + price.toFixed(2);
break;
}
}
}
//-->
</SCRIPT>
<TBODY>
<TR>
<TD width=9 height=1309>&nbsp;</TD>
<TD vAlign=top width=641> <FORM
onsubmit="this.target = 'paypal'; return ReadForm(this, true);"
action=https://www.paypal.com/cgi-bin/webscr method=post name="mfrm">
<P class=mainheadings>
<INPUT type=hidden value=_cart name=cmd>
<INPUT type=hidden value=1 name=add>
<INPUT type=hidden
value=millwalll@aol.com name=business>
<INPUT type=hidden
value="PERSONALISED SIDE WINDOW STICKERS" name=item_name>
<INPUT
type=hidden name=amount>
<INPUT type=hidden value=GBP
name=currency_code>
<input type="hidden" name="pound" value=&pound;>
<INPUT type=hidden value=8.20 name=baseamt>
<INPUT
type=hidden value="PERSONALISED SIDE WINDOW STICKERS" name=basedes>
<INPUT type=hidden value=TEXT name=baseon0>
<INPUT type=hidden
name=baseos0>
<INPUT type=hidden name=on0>
<INPUT type=hidden
name=os0>
<BR>
</P>
<P class=smallbody>Size: 20cm width x 2cm height</P>
<P class=smallbody>TEXT (ARIAL BLACK)
<INPUT size=15
name=first_name_1b>
<BR>
COLOUR
<SELECT name="select">
<OPTION value=WHITE
selected>WHITE</OPTION>
<OPTION value=SILVER>SILVER</OPTION>
<OPTION value=YELLOW>YELLOW</OPTION>
<OPTION
value=RED>RED</OPTION>
<OPTION value=BLUE>BLUE</OPTION>
<OPTION
value=ORANGE>ORANGE</OPTION>
<OPTION value=PURPLE>PURPLE</OPTION>
<OPTION value=GREEN>GREEN</OPTION>
<OPTION
value=GOLD>GOLD</OPTION>
<OPTION value=BLACK>BLACK</OPTION>
</SELECT>
</P>
<P class=smallbody>QUANTITY
<select name="qty" onChange="javascript:updatePrice()">
<option value=1>1</option>
<option value=2>2</option>
<option value=20>20</option>
<option value=40>40</option>
<option value=60>60</option>
<option value=80>80</option>
<option value=100>100</option>
<option value=200>200</option>
</select>
<BR>
<BR>
<BR>
<INPUT type=submit value="Add to Cart" name=submit>
&nbsp; &nbsp; &nbsp; Total item cost
<INPUT class=nbor size=8
value=&pound;8.20 name=tot>
&nbsp;&nbsp; </P>
</FORM>

<FORM action=https://www.paypal.com/cgi-bin/webscr method=post
target=paypal><DIV align=left></DIV>
</FORM></TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
When You Register, These Ads Go Away!
Old 06-20-2005, 04:18 PM
Rufo's Avatar
Extreme Talker

Posts: 173
Any chance you could wrap this in [code] tags and do some indenting? It would make it a lot easier to follow.
__________________
mp3blog.us
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 06-21-2005, 03:47 AM
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
is this ok
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
   <TABLE width="100%" border=0 cellPadding=0 cellSpacing=0 
bgColor=#ffffff id=Table_02b>
   <!--DWLayoutTable-->
<SCRIPT language=JavaScript>
  <!--

    function SymError()
{
    return true;
}

  window.onerror = SymError;

    var SymRealWinOpen = window.open;

      function SymWinOpen(url, name, attributes)
{
return (new Object());
}

   window.open = SymWinOpen;

//-->
</SCRIPT>
   <SCRIPT type=text/javascript>
<!--
     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, tst) { // Read the user form
     var i,j,amt,des,obj,pos,val,op1a="",op1b="",op2a="",op2b="";
       amt = obj1.baseamt.value*1.0; // base amount
         des = obj1.basedes.value; // base description
if (obj1.baseon0) op1a = obj1.baseon0.value; // base options
      if (obj1.baseos0) op1b = obj1.baseos0.value;
  if (obj1.baseon1) op2a = obj1.baseon1.value;
 if (obj1.baseos1) op2b = obj1.baseos1.value;
    for (i=0; i<obj1.length; i++) { // run entire form
     obj = obj1.elements[i]; // a form element
       if (obj.type == "select-one" && // just 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 >= 0) amt = val.substring (pos + 1)*1.0;
           pos = val.indexOf ("+"); // price increment?
    if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
  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
} else
     if (obj.type == "checkbox" || // just get checkboxex
   obj.type == "radio") { // and radios
      if (obj.checked) {
        val = obj.value; // the value of the selection
          pos = val.indexOf ("@"); // price set?
     if (pos >= 0) amt = val.substring (pos + 1)*1.0;
         pos = val.indexOf ("+"); // price increment?
            if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
              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, or text
}
} else
if (obj.type == "select-multiple") { //one or more
       for (j=0; j<obj.options.length; j++) { // run all options
if (obj.options[j].selected) {
     val = obj.options[j].value; // selected value (default)
if (des.length = 0) des = amt;
       else des = des + ", " + val;// accumulate value, or text
pos = val.indexOf ("+"); // price increment?
      if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
}
}
} else
if ((obj.type == "text" || // just read text,
     obj.type == "textarea") &&
obj.name != "tot" && // but not from here
    obj.name != "qty") {
val = obj.value; // get the data
   if (val == "" && tst) { // force an entry
alert ("Enter data for " + obj.name);
return false;
}
tag = obj.name.substring (obj.name.length-2); // get flag
    if (tag == "1a") op1a = op1a + " " + val;
else if (tag == "1b") op1b = op1b + " " + val;
     else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
     else if (des.length == 0) des = val;
else des = des + ", " + val;
}
}
// Now summarize stuff we just processed, above
      if (op1a.length > 0) obj1.on0.value = op1a;
if (op1b.length > 0) obj1.os0.value = op1b;
      if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
      obj1.item_name.value = obj1.qty.options[document.mfrm.qty.selectedIndex].value + " " + des;
obj1.amount.value = Dollar (amt*qty.options[document.mfrm.qty.selectedIndex].value);
}

var arrPrices = [1,8.3,2,8.6,20,14,40,20,60,26,80,32,100,38,200,68];


function updatePrice() {
total = document.mfrm.tot;
quantity = document.mfrm.qty.options[document.mfrm.qty.selectedIndex].value;

for (i=0;i<arrPrices.length;i+=2)
{
    if (quantity == arrPrices[i])
{
i++;
     price = arrPrices[i];
total.value = document.mfrm.pound.value + price.toFixed(2);
   break; 
}
}
}
//-->
</SCRIPT>
    <TBODY>
<TR>
      <TD width=9 height=1309>&nbsp;</TD>
<TD vAlign=top width=641> <FORM 
     onsubmit="this.target = 'paypal'; return ReadForm(this, true);" 
action=https://www.paypal.com/cgi-bin/webscr method=post name="mfrm"> 
     <P class=mainheadings>
<INPUT type=hidden value=_cart name=cmd>
     <INPUT type=hidden value=1 name=add>
<INPUT type=hidden 
      value=millwalll@aol.com name=business>
<INPUT type=hidden 
value="PERSONALISED SIDE WINDOW STICKERS" name=item_name>
<INPUT 
type=hidden name=amount>
    <INPUT type=hidden value=GBP 
name=currency_code>
<input type="hidden" name="pound" value=&pound;>
     <INPUT type=hidden value=8.20 name=baseamt>
<INPUT 
type=hidden value="PERSONALISED SIDE WINDOW STICKERS" name=basedes>
<INPUT type=hidden value=TEXT name=baseon0>
<INPUT type=hidden 
name=baseos0>
<INPUT type=hidden name=on0>
<INPUT type=hidden 
name=os0>
<BR>
</P>
<P class=smallbody>Size: 20cm width x 2cm height</P>
     <P class=smallbody>TEXT (ARIAL BLACK)
<INPUT size=15 
    name=first_name_1b>
<BR>
COLOUR
    <SELECT name="select">
<OPTION value=WHITE 
      selected>WHITE</OPTION>
<OPTION value=SILVER>SILVER</OPTION>
      <OPTION value=YELLOW>YELLOW</OPTION>
<OPTION 
     value=RED>RED</OPTION>
<OPTION value=BLUE>BLUE</OPTION>
<OPTION 
value=ORANGE>ORANGE</OPTION>
     <OPTION value=PURPLE>PURPLE</OPTION>
<OPTION value=GREEN>GREEN</OPTION>
    <OPTION 
      value=GOLD>GOLD</OPTION>
<OPTION value=BLACK>BLACK</OPTION>
</SELECT>
</P>
<P class=smallbody>QUANTITY
      <select name="qty" onChange="javascript:updatePrice()">
         <option value=1>1</option>
     <option value=2>2</option>
<option value=20>20</option>
     <option value=40>40</option>
<option value=60>60</option>
    <option value=80>80</option>
<option value=100>100</option>
     <option value=200>200</option>
</select>
<BR>
<BR>
<BR>
<INPUT type=submit value="Add to Cart" name=submit>
    &nbsp; &nbsp; &nbsp; Total item cost
<INPUT class=nbor size=8 
    value=&pound;8.20 name=tot>
&nbsp;&nbsp; </P>
</FORM>

<FORM action=https://www.paypal.com/cgi-bin/webscr method=post 
target=paypal><DIV align=left></DIV>
</FORM></TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 06-21-2005, 05:26 PM
Rufo's Avatar
Extreme Talker

Posts: 173
Thanks, but I don't think you've got the idea of indenting - it is supposed to reflect the hierarchical nature of the code and make it easier to follow.

Quote:
Originally Posted by Rufo
Any chance you could wrap this in [code] tags?
I actually meant edit your original post, so there aren't several pages of code, not post it all again

Quote:
Originally Posted by millwalll
obj1.amount.value = Dollar (amt*qty.options[document.mfrm.qty.selectedIndex].value);
Do you not mean document.mfrm.amount.value?
__________________
mp3blog.us
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 06-22-2005, 04:45 AM
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
hi well ive got no clue about java script at all this is a code i asked somone to build for me and he got it this far that workds fine it just dont work when u say add to basket it comes up with a zero value so trying to sort this out
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 07-04-2005, 05:35 AM
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
so can anyone help with this java problem as i need this for my new site
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 07-11-2005, 07:51 PM
Rufo's Avatar
Extreme Talker

Posts: 173
Quote:
Originally Posted by millwalll
so can anyone help with this java problem as i need this for my new site
Firstly, it's javascript, not java. They are totally different languages.

Have you tried my previous suggestion?
__________________
mp3blog.us
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-12-2005, 03:47 AM
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
no because i dont know anyhtink about javascript
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Old 07-12-2005, 08:51 AM
Rufo's Avatar
Extreme Talker

Posts: 173
I've told you the alteration you should try.
I am not willing to offer any more help until I know the results of my first suggestion.

Quote:
Originally Posted by Rufo
Quote:
Originally Posted by millwalll
obj1.amount.value = Dollar (amt*qty.options[document.mfrm.qty.selectedIndex].value);
Do you not mean document.mfrm.amount.value?
__________________
mp3blog.us
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 07-12-2005, 09:15 AM
millwalll's Avatar
Webmaster Talker

Posts: 554
Name: James
Location: KENT
can you tell me where in the script i need to change it then as i have tried it but not sure if it the right things if it is then it does nothink
millwalll is offline
Reply With Quote
View Public Profile Visit millwalll's homepage!
 
Reply     « Reply to need help with javascript problem need exclent java programer
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.18641 seconds with 12 queries