Hi
I wonder if someone can help me. I have a web order page with drop down boxes which are currently un-named selects, eg.
<select onchange = "ReadForm(this.form)" span class="blue">
<option value="+-0.00"></option>
<option class="blue" value="A +10.00">A</option>
<option class="blue" value="B +15.00">B</option>
<option class="blue" value="C +20.00">C</option>
</select>
with a javascript readform to concatenate the un-named selects' values and pass them to paypal:
<script type="text/javascript">
function ReadForm (obj1) { // process un-named selects
var i,amt,des,obj,pos,val;
amt = obj1.baseamt.value*1.0; // 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 > 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
}
}
obj1.item_name.value = des;
obj1.amount.value = Pound (amt);
if (obj1.tot) obj1.tot.value = "£" + Pound (amt);
}
//-->
</script>
... This works fine but I need to add some functionality to it. I want dependent drop down boxes, so that the selection made in drop down box A influences the available options in drop down box B, etc. An example of code I have for this is as follows:
<Script Language="VBScript">
Sub RunScript
For Each objOption in DynamicOptions.Options
objOption.RemoveNode
Next
If PickCategory.Value = "Characters" Then
arrValues = Array("A", "B", "C", "D", "E")
End If
If PickCategory.Value = "Numbers" Then
arrValues = Array("1", "2", "3", "4", "5")
End If
For Each strValue in arrValues
Set objOption = Document.createElement("OP
TION")
objOption.Text = strValue
objOption.Value = strValue
DynamicOptions.Add(objOpti
on)
Next
End Sub
</Script>
<select size="1" name="PickCategory" style="width:100px" onChange="RunScript">
<option value="Characters">Charact
ers</optio
n>
<option value="Numbers">Numbers</o
ption>
</select>
<P>
<select size="1" name="DynamicOptions" style="width:100px">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
Which in itself works fine and I can easily add the other options etc., but
1. How do I increment the total price when using the above dynamic options lists? Is there a way of having all the values in the code but greyed out for the user? Would that be correct?
2. How do I deal with the fact they are now named selects and how do I pass them to the readform.
Apologies if I'm going about this all wrong, any advice on how to make what I've got work or alternative methods would be much appreciated.
All the best
Al
Start Free Trial