By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,627 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,627 IT Pros & Developers. It's quick & easy.

multiple functions within same combo box

P: 1
i'm trying to make a very simple combo box which will act as a shopping cart for my website where i will be selling some art prints; ideally once a visitor selects a print title in the combo box, script should display a small thumbnail of the print, calculate the price depending on size and quantity and then re-direct visitor to PayPal.

everything works more or less ok apart from the display of thumbnails which should depend on the selected value (title) in the combo box

i have another script - some drop down image selector - which displays images like i want but i can't tie the shopping cart script to it

any suggestions of what can be done?

===script used====

[HTML]<html>
<head>
<title>New Page 2</title>

<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) { // process selects
var i,j,amt=0,des="",obj,pos,tok,val,
op1a="",op1b="",op2a="",op2b="",itmn="";
var ary = new Array ();
if (obj1.baseamt) amt = obj1.baseamt.value*1.0; // base amount
if (obj1.basedes) 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;
if (obj1.baseitn) itmn = obj1.baseitn.value;
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
if (obj.name == "quantity" || // don't mess with these
obj.name == "amount") continue;
pos = obj.selectedIndex; // which option selected
val = obj.options[pos].value; // selected value
ary = val.split (" "); // break apart
for (j=0; j<ary.length; j++) { // look at all items
// first we do single character tokens...
if (ary[j].length < 2) continue;
tok = ary[j].substring (0,1); // first character
val = ary[j].substring (1); // get data
if (tok == "@") amt = val * 1.0;
if (tok == "+") amt = amt + val*1.0;
if (tok == "%") amt = amt + (amt * val/100.0);
if (tok == "#") { // record item number
if (obj1.item_number) obj1.item_number.value = val;
ary[j] = ""; // zap this array element
}
// Now we do 3-character tokens...
if (ary[j].length < 4) continue;
tok = ary[j].substring (0,3); // first 3 chars
val = ary[j].substring (3); // get data
if (tok == "s1=") { // value for shipping
if (obj1.shipping) obj1.shipping.value = val;
ary[j] = ""; // clear it out
}
if (tok == "s2=") { // value for shipping2
if (obj1.shipping2) obj1.shipping2.value = val;
ary[j] = ""; // clear it out
}
}
val = ary.join (" "); // rebuild val with what's left

if (obj.name == "on0" || // let these go where they want
obj.name == "os0" ||
obj.name == "on1" ||
obj.name == "os1") continue;

tag = obj.name.substring (obj.name.length-2); // get flag
if (tag == "1a") op1a = op1a + " " + val; // stuff data
else if (tag == "1b") op1b = op1b + " " + val;
else if (tag == "2a") op2a = op2a + " " + val;
else if (tag == "2b") op2b = op2b + " " + val;
else if (tag == "3i") itmn = itmn + " " + 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; // stuff it away
if (op1b.length > 0) obj1.os0.value = op1b;
if (op2a.length > 0) obj1.on1.value = op2a;
if (op2b.length > 0) obj1.os1.value = op2b;
if (itmn.length > 0) obj1.item_number.value = itmn;
obj1.item_name.value = des;
obj1.amount.value = Dollar (amt);
if (obj1.tot) obj1.tot.value = "" + Dollar (amt);
}
//-->
</script>
</head>

<body>

<!-- This is the FORM to view the cart contents -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="viewcart" name="viewcart">
<p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="display" value="1" />
<input type="hidden" name="business" value="abc@test.co.uk" />
</p>
</form>
<!-- End of view cart FORM -->

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"
onsubmit="this.target = 'paypal';
ReadForm (this);">
<p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="abc@test.co.uk" />
<input type="hidden" name="item_name" value="" />
<input type="hidden" name="amount" value="" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="lc" value="US" />

<input type="hidden" name="baseamt" value="0.00" /><!--base price for the artwork-->
<input type="hidden" name="basedes" value="Print" />

<input type="hidden" name="on0" value="" />
<input type="hidden" name="os0" value="" />
<input type="hidden" name="on1" value="" />
<input type="hidden" name="os1" value="" />
<input type="hidden" name="item_number" value="" />

<input type="hidden" name="baseon0" value="Title" />
<input type="hidden" name="baseos0" value="" />
<input type="hidden" name="baseon1" value="Size" />
<input type="hidden" name="baseos1" value="" />
<input type="hidden" name="baseitn" value="" />

<br /><br />

<table>

<tr><td>
Picture: </td><td>
<select onchange = "ReadForm (this.form);" name=type_1b>
<option value="YOU FORGOT TO SELECT THE PICTURE!">Select Your Picture</option>
<option value="Body Geometry">Body Geometry</option>
<option value="Unfree">Unfree</option>
</select>
</td>
<td rowspan=5>
Quantity:
<input type="text" name="quantity" size="3" value="1" />
&nbsp;

Total:
<input class="nbor" type="text" name="tot" size="8" value="0.00" /><!-- this is your base cost, if you have one-->
&nbsp;

<br><center>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" name="submit" alt="cart add" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_viewcart_SM.gif" alt="cart view"
onclick="document.forms.viewcart.target = 'paypal';
document.forms.viewcart.submit ();
return false;" /><br>
<INPUT TYPE="reset" VALUE="Reset Form">
</center>
</td>

</tr>

<tr><td>
Size: </td><td>
<select name="size_2b" onchange = "ReadForm (this.form);">
<option value="">Choose Size</option>
<option value="10x10 in / 25x25 cm +66.98">10x10 in / 25x25 cm</option>
<option value="10x12 in / 25x30 cm +72.85">10x12 in / 25x30 cm</option>
<option value="10x14 in / 25x35 cm +75.20">10x14 in / 25x35 cm</option>
<option value="10x16 in / 25x40 cm +81.08">10x16 in / 25x40 cm</option>
</select>
</td></tr>
</table>
<br /><br />
</p>
</form>

</body>
</html>[/HTML]
Jan 20 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Which image do you want to change?
Jan 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.