473,486 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using dropdown / dynamic display change

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.
Jun 8 '07 #1
4 5238
On Jun 8, 4:27 pm, J MCallister <J...@nospam.comwrote:
>
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.
I don't understand, why can't you just assign a function
to the onchange handler to the select after the fact?

document.getElementById('ShippingMethod').onchange =function(){...}

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.
A regular expression would do this easily.

---
Geoff

Jun 8 '07 #2

>
I don't understand, why can't you just assign a function
to the onchange handler to the select after the fact?

document.getElementById('ShippingMethod').onchange =function(){...}
So that would be in its own function and then is called how?

>
>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.

A regular expression would do this easily.
Er.. this I don't get at all, yet. Or how the above handler will change
once I do get it.

I'm goggling now, but any further hints at how on both of these would be
greatly appreciated.
Jun 8 '07 #3
I'm sort of getting it but I am stuck
The way I figured out how to make this function when I was able to put
an onchange event handler like this:

<select name="ShippingMethod"
onChange="this.form.price1.value=this.options
[this.selectedIndex].id;tota
l();">

What this does is change the value of a hidden field in the form called
price1 to whatever value is assigned to the option id. That worked
fine.

But when I try to do it this way:

<script type="text/javascript">
document.getElementById
('ShippingMethod').onChange=this.form.price1.value
=this.options[this.selectedIndex].id;total(); </script>

It doesn't work. Something is not right with the syntax I think when
doing it this way.

The function total(); triggers fine. But the rest of it doesn't work.

DO I need to move this:

this.form.price1.value=this.options[this.selectedIndex].id

out of the above block, put it in is own function and then call that?

Help, silt vouz plait!
>
>>
I don't understand, why can't you just assign a function
to the onchange handler to the select after the fact?

document.getElementById('ShippingMethod').onchang e=function(){...}

So that would be in its own function and then is called how?

>>
>>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.

A regular expression would do this easily.

Er.. this I don't get at all, yet. Or how the above handler will
change once I do get it.

I'm goggling now, but any further hints at how on both of these would
be greatly appreciated.


Jun 9 '07 #4
On Jun 8, 10:02 pm, J MCallister <J...@nospam.comwrote:
I'm sort of getting it but I am stuck

The way I figured out how to make this function when I was able to put
an onchange event handler like this:

<select name="ShippingMethod"
onChange="this.form.price1.value=this.options
[this.selectedIndex].id;tota
l();">

What this does is change the value of a hidden field in the form called
price1 to whatever value is assigned to the option id. That worked
fine.

But when I try to do it this way:

<script type="text/javascript">
document.getElementById
('ShippingMethod').onChange=this.form.price1.value
=this.options[this.selectedIndex].id;total(); </script>

It doesn't work. Something is not right with the syntax I think when
doing it this way.

The function total(); triggers fine. But the rest of it doesn't work.

DO I need to move this:

this.form.price1.value=this.options[this.selectedIndex].id

out of the above block, put it in is own function and then call that?
Try this...

var select=document.getElementById('ShippingMethod');
select.onchange=
function(elem)
{
return function()
{
var option=elem.options[elem.selectedIndex];
var str=/\(\$(.*)\)/.exec(option.innerHTML);
if(str)
{
var id=str[1];
window.alert(id);
}
}
}(select);

----
Geoff

Jun 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
9581
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
3
10723
by: Robert Mark Bram | last post by:
Hi All! Has anyone seen an example of the following javascript powered control: - a dropdown select menu - the width of the control is set. Assume by "control" I mean the visible part of the...
7
8477
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
1
1328
by: sk | last post by:
I have a situation where the list of tables(database) and the columns for each table must be displayed for selection. for each member(displayed in each row) i have to select a table and a column from...
3
3013
by: sewerized | last post by:
Hello all, I'm having a problem with a user preferences form I'm creating. I want to use dynamic dropdown SELECT boxes for this so my page doesn't get cluttered with 100000 links. Since I...
0
2893
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
4
2603
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
1
2642
by: luispunchy | last post by:
I have an accordion style dropdown list/sublist menu (functions similar to the "today on WebMD video" widget found on http://www.webmd.com/) - it will allow users to click on a headline (from the...
1
2682
by: SunshineInTheRain | last post by:
The following code is dynamic create dropdownmenu which data within pulled from database However, the code work well on IE but not on Firefox. On Firefox, the whole mouseover and mouseout function...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.