Advertisement

07.19.2008 at 12:14PM PDT, ID: 23579359 | Points: 500
[x]
Attachment Details

Having trouble integrating dynamic dependent drop downs and calculation of total price

Asked by Aljeebo in JavaScript, VB Script

Tags:

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("OPTION")
            objOption.Text = strValue
            objOption.Value = strValue  
            DynamicOptions.Add(objOption)
        Next    
    End Sub
</Script>

<select size="1" name="PickCategory" style="width:100px" onChange="RunScript">
    <option value="Characters">Characters</option>
    <option value="Numbers">Numbers</option>
</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

AlStart Free Trial
[+][-]07.20.2008 at 11:10AM PDT, ID: 22046446

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 12:06PM PDT, ID: 22046589

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 01:02PM PDT, ID: 22046745

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 05:50PM PDT, ID: 22047574

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 12:24AM PDT, ID: 22057015

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 03:34PM PDT, ID: 22064322

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.28.2008 at 02:31AM PDT, ID: 22101681

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.03.2008 at 11:49PM PDT, ID: 22150373

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.04.2008 at 08:03AM PDT, ID: 22153022

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628