J
J MCallister
Hello, I am working on a shopping cart where the viewer sees a dropdown
with shipping options, each with a price.
Elsewhere on the page is a display of the total.
I am working on having the dropdown update the total when a different
option is selected.
So far I have it worked out doing it this way:
<form name="form2"
<input type="text" name="total_price" value="56.54" readonly>
</form>
That is the display of the current total
<select name="ShippingMethod" onChange="
this.form.price2.value=this.options[this.selectedIndex].id;ship
();this.form.price1.value=this.options[this.selectedIndex].id;total();">
name="total_price"<option value="">Select One</option>
<option value="Standard" id="5.49">Standard Shipping($5.49)</option>
<option value="Expedited" id="9.99">Expedited Shipping ($9.99)</option>
<option value="Rush" id="14.99">Rush Shipping ($14.99)</option>
</select>
The above is the dropdown.
FOr the sake of brevity I have left out all the javascript functions,
but you can see the basics of what is going on. Changing the dropdown
will take whatever value is in the option id="x.xx" and add it to the
"total_price" field in "form2"
That works just fine.
But I have a problem now.
I have to figure out a way to do the same in a case where I *do not*
have the ability to modify the dropdown. In that case it is going to end
up on the page very plainly like this:
<select name="ShippingMethod">
<option value="">Select One</option>
<option value="Standard">Standard Shipping($5.49)</option>
<option value="Expedited">Expedited Shipping ($9.99)</option>
<option value="Rush">Rush Shipping ($14.99)</option>
</select>
I cannot get in there to add the onchange event handler, nor get the
id="x.xx" to the options for the amount to add. The dropdown is
generated by a closed source 3rd party application and I have no ability
to modify its output.
Is it going to be possible to replicate the functionality? I guess
somehow I need to take the string presented inside each option such as:
Standard Shipping($5.49)
and discard everything except what is between the parenthesis, discard
the dollar sign and hold the result in a variable, do that for every
option and go from there.
If anyone could chime in and give me some thoughts on how to accomplish
this, I would appreciate it as right now it is beyond my understanding.
with shipping options, each with a price.
Elsewhere on the page is a display of the total.
I am working on having the dropdown update the total when a different
option is selected.
So far I have it worked out doing it this way:
<form name="form2"
<input type="text" name="total_price" value="56.54" readonly>
</form>
That is the display of the current total
<select name="ShippingMethod" onChange="
this.form.price2.value=this.options[this.selectedIndex].id;ship
();this.form.price1.value=this.options[this.selectedIndex].id;total();">
name="total_price"<option value="">Select One</option>
<option value="Standard" id="5.49">Standard Shipping($5.49)</option>
<option value="Expedited" id="9.99">Expedited Shipping ($9.99)</option>
<option value="Rush" id="14.99">Rush Shipping ($14.99)</option>
</select>
The above is the dropdown.
FOr the sake of brevity I have left out all the javascript functions,
but you can see the basics of what is going on. Changing the dropdown
will take whatever value is in the option id="x.xx" and add it to the
"total_price" field in "form2"
That works just fine.
But I have a problem now.
I have to figure out a way to do the same in a case where I *do not*
have the ability to modify the dropdown. In that case it is going to end
up on the page very plainly like this:
<select name="ShippingMethod">
<option value="">Select One</option>
<option value="Standard">Standard Shipping($5.49)</option>
<option value="Expedited">Expedited Shipping ($9.99)</option>
<option value="Rush">Rush Shipping ($14.99)</option>
</select>
I cannot get in there to add the onchange event handler, nor get the
id="x.xx" to the options for the amount to add. The dropdown is
generated by a closed source 3rd party application and I have no ability
to modify its output.
Is it going to be possible to replicate the functionality? I guess
somehow I need to take the string presented inside each option such as:
Standard Shipping($5.49)
and discard everything except what is between the parenthesis, discard
the dollar sign and hold the result in a variable, do that for every
option and go from there.
If anyone could chime in and give me some thoughts on how to accomplish
this, I would appreciate it as right now it is beyond my understanding.