PDA

View Full Version : Need to pre-select a form option


RTMac
02-20-2004, 10:49 AM
I have found a script that lets you modify the shipping information in a PayPal cart. The code as written lets you select from five different shipping methods from a list in an html form.

I need to simplify this code a bit. I only want to offer UPS shipping. In html I could just a hidden field to pass the shipping variable, but I am not sure how to do that in JavaScript.

Any help would be appreciated!

Here is the form code:

<script type="text/javascript">
document.writeln ('<select onchange = "Shipper (this);">',
' <option selected>Select/Modify Shipping</option>',
' <option>USPS Priority Insured</option>',
' <option>USPS Priority Uninsured</option>',
' <option>USPS Parcel Post Uninsured</option>',
' <option>UPS Ground Uninsured</option>',
' <option>WILL PICK UP</option>',
'</select>',
'

');


And here is the Shipper function it calls. (I see that the UPS option is refered to as 'position 4'):

function Shipper (obj1) { // use either amt or qty based shipping
var pos;
SetAmtSH (0); // assume the worst
SetCartSH (0);
pos = obj1.selectedIndex; // which option selected
root.stxt0 = obj1.options[pos].text;
if (pos == 1) { // 1st option
usps = 1;
uspp = -1;
ups = -1;
insu = 1;
zip = prompt("Enter destination ZIP...", "").substring (0, 3);
if (isNaN (zip)) { // keep them honest
alert ("You must enter a valid ZIP code!");
usps = -1; // zap evferything
insu = -1;
return;
}
CalcCost ();
} else
if (pos == 2) { // 2nd option
usps = 1;
uspp = -1;
ups = -1;
insu = -1;
zip = prompt("Enter destination ZIP...", "").substring (0, 3);
if (isNaN (zip)) { // keep them honest
alert ("You must enter a valid ZIP code!");
usps = -1;
return;
}
CalcCost ();
} else
if (pos == 3) { // 3rd option
usps = -1;
uspp = 1;
ups = -1;
insu = -1;
zip = prompt("Enter destination ZIP...", "").substring (0, 3);
if (isNaN (zip)) { // keep them honest
alert ("You must enter a valid ZIP code!");
uspp = -1;
return;
}
CalcCost ();
} else
if (pos == 4) { // 4th option
usps = -1;
uspp = -1;
ups = 1;
insu = -1;
zip = prompt("Enter destination ZIP...", "").substring (0, 3);
if (isNaN (zip)) { // keep them honest
alert ("You must enter a valid ZIP code!");
ups = -1;
return;
}
CalcCost ();
} else
if (pos == 5) { // 5th option
usps = -1;
uspp = -1;
ups = -1;
insu = -1;
root.usps = -1;
root.uspp = -1;
root.ups = -1;
root.insu = -1;
SetCartSH (0, 0, 0);
}
SetAmtSH (0,0,0); // LEAVE ALONE!!
document.location.reload (); // show the latest info...
}