The link below is my form
[URL=”http://retouchingphotos.co.uk/send-us-your-photos.html”]http://retouchingphotos.co.uk/send-us-your-photos.html
*Please note: Honestly, I copy-pasted it from an asp-based site and modified the form according to my services. The site owner warned me it would cause problems as my site is Html-based only.
This form collects info of the customer who wishes to select add-ons that would be applied to their digital photos. Examples of add-ons:
[LIST][*]
Photo makeover
Add object or person
Crop image
Once a customer does the following:
[LIST=1][*]
select a Package (e.g. Photo Manipulation)
select one or more Add-ons (e.g. Add object or person, Cropping etc )
enter their details
hit the submit button
it then takes them to the PayPal checkout page where the total amount is shown.
[B]Problem:
In the PayPal page, it shows t “Add object or person” as well as names of all the 5 Packages no matter what add-ons I select.
This is a problem since I will not know exactly what add-ons the customer has chosen after they make payment.
[B]Specifics
In order to send the add-ons the customer selects I may have to use the onX and osX variables (Where X is a number starting with 0 and incrementing by 1 see below), These can be used to set options for the add-ons they select. The onO is the “option name” and os0 is the “option choice”. So for example the two lines would be
<input type=”hidden” name=”on0″ value=”Photo manipulation”>
<input type=”hidden” name=”os0″ value=”Whatever addons the customer selects”>
<input type=”hidden” name=”on1″ value=”Photo restoration”>
<input type=”hidden” name=”os1″ value=”Whatever addons the customer selects”>
.
.
.
I need to populate the value of os0, os1, os2 etc etc using Javascript depending on the Add-ons the customer selects.
Can you help? Thank you for reading and I look forward to your replies.
Kind Regards
Rafi
[CODE]
function addInput(obj,_typ,_nam,_val){
newInput=document.createElement('input');
newInput.setAttribute("type",_typ);
newInput.setAttribute("name",_nam);
newInput.setAttribute("value",_val);
obj.appendChild(newInput);
}
function newPPoption(_form,optname,optvalue){
_allInputs=document.getElementsByTagName('input');
PPoptions=[];
PPregex=/^ond+$/i;
for(i=0;i<_allInputs.length;i++){
if(_allInputs[i].type=='hidden' && PPregex.test(_allInputs[i].name)) {PPoptions.push(_allInputs[i]);}
}
PPopSort=PPoptions.sort();
_max=parseInt(PPopSort[PPopSort.length-1].name.match(/d+/),10);
addInput(_form,"hidden","on"+(_max+1),optname);
addInput(_form,"hidden","os"+(_max+1),optvalue);
}
[/CODE]
[CODE]
newPPoption(document.forms["PP_form_name"],"new option name","new option choice");
[/CODE]
Just get the name of the form you want to add the inputs to and plug it in the above call, as well as your option name and option choice.[/QUOTE]
[CODE]<FORM action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal">
[/CODE]
[CODE]newPPoption(document.forms["PP_paypal"],"Photo manipulation","Add object or person");[/CODE]
[CODE]function addInput(obj,_typ,_nam,_val){
newInput=document.createElement('input');
newInput.setAttribute("type",_typ);
newInput.setAttribute("name",_nam);
newInput.setAttribute("value",_val);
obj.appendChild(newInput);
}
function newPPoption(_form,optname,optvalue){
_allInputs=document.getElementsByTagName('input');
PPoptions=[];
PPregex=/^ond+$/i;
for(i=0;i<_allInputs.length;i++){
if(_allInputs[i].type=='hidden' && PPregex.test(_allInputs[i].name)) {PPoptions.push(_allInputs[i]);}
}
PPopSort=PPoptions.sort();
_max=parseInt(PPopSort[PPopSort.length-1].name.match(/d+/),10);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_1"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_2"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_3"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_4"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_5"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_6"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_7"+(_max+1),optvalue);
addInput(_form,"hidden","on0_1"+(_max+1),optname);
addInput(_form,"hidden","os0_8"+(_max+1),optvalue);
}[/CODE]
[CODE]
newPPoption(document.forms["paypal"],"Photo manipulation","Add object or person");
newPPoption(document.forms["paypal"],"Photo manipulation","Viginette");
newPPoption(document.forms["paypal"],"Web Page Design","Simple static page");
newPPoption(document.forms["paypal"],"Another Option","Another choice for the option");
etc...
[/CODE]
[CODE]
function addInput(obj,_typ,_nam,_val){
newInput=document.createElement('input');
newInput.setAttribute("type",_typ);
newInput.setAttribute("name",_nam);
newInput.setAttribute("value",_val);
obj.appendChild(newInput);
}
function newPPoption(_form,optname,optvalue){
_allInputs=document.getElementsByTagName('input');
PPoptions=[];
PPregex=/^ond+$/i;
for(i=0;i<_allInputs.length;i++){
if(_allInputs[i].type=='hidden' && PPregex.test(_allInputs[i].name)) {PPoptions.push(_allInputs[i]);}
}
PPopSort=[];
PPopSort=PPoptions.sort();
_max=PPopSort.length>0?parseInt(PPopSort[PPopSort.length-1].name.match(/d+/),10):-1;
addInput(_form,"hidden","on"+(_max+1),optname);
addInput(_form,"hidden","os"+(_max+1),optvalue);
}
[/CODE]
[CODE]PPopSort=[];
[/CODE]
[CODE]Photo manipulation: Add object or person
Photo manipulation: Cropping
Photo manipulation: Photo makeover
Photo manipulation: Replacing background
Photo manipulation: Remove object or person
Photo manipulation: Colour photo to sepia
Photo manipulation: Convert colour photo to black and white
Photo manipulation: Convert black and white to colour
Photo restoration: Add colour to black & white photos
Photo restoration: Minor repair
Photo restoration: Major repair
Photo retouching: Change eye colour
Photo retouching: Change lip colour
Photo retouching: Brighten teeth
Photo retouching: Brighten eyes
Photo retouching: Nose correction
Photo retouching: Add shine
Photo retouching: Remove pores
Photo retouching: Remove scars
Photo retouching: Remove wrinkles
Photo retouching: Remove facial lines
Photo retouching: Improve complexion
Photo retouching: Colour correction
Photo retouching: Face slimming
Photo retouching: Skin lightening
Photo retouching: Colour photo to sepia
Photo retouching: From colour photo to black and white
Photo retouching: From black and white to colour
Special effects: Insert background
Special effects: Cartoonise your photo
Special effects: Robotize your photo
Special effects: Panorama photo effects
Special effects: Spot light
Website package offer: Online portfolio website
Website package offer: Online model website
Website package offer: Online wedding album website
Website package offer: Online children album website
Website package offer: Online family album website[/CODE]
[CODE] <SCRIPT language="javascript" type="text/javascript">
function addInput(obj,_typ,_nam,_val){
newInput=document.createElement('input');
newInput.setAttribute("type",_typ);
newInput.setAttribute("name",_nam);
newInput.setAttribute("value",_val);
obj.appendChild(newInput);
}
function newPPoption(_form,optname,optvalue){
_allInputs=document.getElementsByTagName('input');
PPoptions=[];
PPregex=/^ond+$/i;
for(i=0;i<_allInputs.length;i++){
if(_allInputs[i].type=='hidden' && PPregex.test(_allInputs[i].name)) {PPoptions.push(_allInputs[i]);}
}
PPopSort=[];
PPopSort=PPoptions.sort();
_max=PPopSort.length>0?parseInt(PPopSort[PPopSort.length-1].name.match(/d+/),10):-1;
addInput(_form,"hidden","on"+(_max+1),optname);
addInput(_form,"hidden","os"+(_max+1),optvalue);
}
</SCRIPT>[/CODE]
[CODE]<SCRIPT language="javascript" type="text/javascript">
newPPoption(document.forms["paypal"],"Photo manipulation","Add object or person");
newPPoption(document.forms["paypal"],"Photo manipulation","Cropping");
newPPoption(document.forms["paypal"],"Photo manipulation","Photo makeover");
newPPoption(document.forms["paypal"],"Photo manipulation","Replacing background");
newPPoption(document.forms["paypal"],"Photo manipulation","Remove object or person");
newPPoption(document.forms["paypal"],"Photo manipulation","Colour photo to sepia");
newPPoption(document.forms["paypal"],"Photo manipulation","Convert colour photo to black and white");
newPPoption(document.forms["paypal"],"Photo manipulation","Convert black and white to colour");
newPPoption(document.forms["paypal"],"Photo restoration","Add colour to black & white photos");
newPPoption(document.forms["paypal"],"Photo restoration","Minor repair");
newPPoption(document.forms["paypal"],"Photo restoration","Major repair");
newPPoption(document.forms["paypal"],"Photo retouching","Change eye colour");
newPPoption(document.forms["paypal"],"Photo retouching","Change lip colour");
newPPoption(document.forms["paypal"],"Photo retouching","Brighten teeth");
newPPoption(document.forms["paypal"],"Photo retouching","Brighten eyes");
newPPoption(document.forms["paypal"],"Photo retouching","Nose correction");
newPPoption(document.forms["paypal"],"Photo retouching","Add shine");
newPPoption(document.forms["paypal"],"Photo retouching","Remove pores");
newPPoption(document.forms["paypal"],"Photo retouching","Remove scars");
newPPoption(document.forms["paypal"],"Photo retouching","Remove wrinkles");
newPPoption(document.forms["paypal"],"Photo retouching","Remove facial lines");
newPPoption(document.forms["paypal"],"Photo retouching","Improve complexion");
newPPoption(document.forms["paypal"],"Photo retouching","Colour correction");
newPPoption(document.forms["paypal"],"Photo retouching","Face slimming");
newPPoption(document.forms["paypal"],"Photo retouching","Skin lightening");
newPPoption(document.forms["paypal"],"Photo retouching","Colour photo to sepia");
newPPoption(document.forms["paypal"],"Photo retouching","From colour photo to black and white");
newPPoption(document.forms["paypal"],"Photo retouching","From black and white to colour");
newPPoption(document.forms["paypal"],"Special effects","Insert background");
newPPoption(document.forms["paypal"],"Special effects","Cartoonise your photo");
newPPoption(document.forms["paypal"],"Special effects","Robotize your photo");
newPPoption(document.forms["paypal"],"Special effects","Panorama photo effects");
newPPoption(document.forms["paypal"],"Special effects","Spot light ");
newPPoption(document.forms["paypal"],"Website package offer","Online portfolio website");
newPPoption(document.forms["paypal"],"Website package offer","Online model website");
newPPoption(document.forms["paypal"],"Website package offer","Online wedding album website");
newPPoption(document.forms["paypal"],"Website package offer","Online children album website");
newPPoption(document.forms["paypal"],"Website package offer","Online family album website");
</SCRIPT>[/CODE]
[CODE]
By the way, look closely at the statement which defines "_max". PPopSort=[]; was there just to throw you off my trail . Just kidding, that was one of the things I changed, but the important one was that I used the ternary operator "?:" to check if there was anything in the array yet. The "PPopSort=[];" statement just defines an empty array so that when I check to see if it has anything in it, it doesn't return "undefined".[/CODE]
[CODE]
function submitForm(){
_formInputs=document.getElementsByTagName('inputs');
_checkboxes=[];
for(i=0;i<_formInputs.length;i++){
if(_formInputs[i].type=='checkbox') _checkBoxes.push(_formInputs[i]);
}
for(i=o;i<_checkboxes.length;i++){
if(_checkboxes[i].checked) {
optionName=????????????????; //I don't know how you'll determine this part.
optionChoice=_checkboxes[i].parentNode.getElementsByTagName('label')[0].value;
newPPoption(document.forms["paypal"],optionName,optionChoice);
}
}
document.forms["paypal"].submit();
}[/CODE]
[CODE] <INPUT type="hidden" name="cmd" value="_cart">
<INPUT type="hidden" name="add" value="1">
<INPUT type="hidden" name="business" value="my paypal email address">
<input type="hidden" name="currency_code" value="GBP">
<INPUT type="hidden" name="receiver_email" value="my paypal email address">
<INPUT type="hidden" name="item_name" value="Add object or person">
<INPUT type="hidden" name="amount" id="amount" value="9.99">
[/CODE]
[CODE] <INPUT type="hidden" name="item_name" value="Add object or person">
<INPUT type="hidden" name="amount" id="amount" value="9.99">[/CODE]
[CODE] <INPUT type="hidden" name="cmd" value="_cart">
<INPUT type="hidden" name="add" value="1">
<INPUT type="hidden" name="business" value="[email protected]">
<input type="hidden" name="currency_code" value="GBP"> <!-- currency -->
<INPUT type="hidden" name="return" value="http://www.url.com/contact-us.html">
<INPUT type="hidden" name="cancel_return" value="http://www.url.com/send-us-your-photos.html">
<INPUT type="hidden" name="receiver_email" value="[email protected]">
<INPUT type="hidden" name="item_name" value="Add object or person">
<INPUT type="hidden" name="amount" id="amount" value="9.99">
[/CODE]
[CODE]
<INPUT type="hidden" name="item_name" value="Add object or person">
<INPUT type="hidden" name="amount" id="amount" value="9.99">[/CODE]
[CODE]Change your form to method="POST" instead of method="post" and add enctype="multipart/form-data" [/CODE]
By the way I removed the JavaScript code from the head and the one after the form which you suggested earlier. [/QUOTE]
[CODE]
You might try something like this in HTML:
<input id=”on0” type="hidden" name="on0" value="Photo manipulation">
<input id=”os0” type="hidden" name="os0" value="Whatever addons the customer selects">
With this corresponding javascript:
var on0 = document.getElementById('on0');
on0.setAttribute("on0", "My Desired value”);[/CODE]
[CODE] <INPUT type="hidden" name="item_name" value="Add object or person">
<INPUT type="hidden" name="amount" id="amount" value="9.99">[/CODE]
[CODE]
<INPUT type="hidden" name="item_name" value="Retouching Photos">
<INPUT type="hidden" name="amount" id="amount" value="">
[/CODE]
[CODE]
if($cbregexp.test(_checkboxes.getAttribute("id")) && _checkboxes[i].checked) {
[/CODE]
[CODE]
if($cbregexp.test(_checkboxes[COLOR="Red"][B][i][/B][/COLOR].getAttribute("id")) && _checkboxes[i].checked) {
[/CODE]
[CODE]
$cbregexp=/cbAddOns/;
[/CODE]
[CODE]
$cbregexp=/cb[COLOR="Red"][B]l[/B][/COLOR]AddOns/;
[/CODE]
[CODE]Special: Insert background (£3.99)
Special: Cartoonise your photo (£4.99)
Special: Robotize your photo (£5.99)
Special: Panorama photo effects (£6.99)
Special: Spot light (£7.99)[/CODE]
[code=html]
£
[/CODE]
0.1.9 — BETA 6.16