retrieving the choise of a combo box

K

Klaas Seelen

Hi,

On a webpage I have three comboboxes. The second and the third are
dynamically filled dependent from the choice in the first combobox.
Each choice in all three boxes consist of a numeric value and a
string. This is done through a javascript and it uses the numeric
values of the first box. When submitting the page to an asp script I
don't want to post these numeric values but the selected strings. Can
this be done???

Regards, Klaas Seelen
 
B

Bob Barrows [MVP]

Klaas said:
Hi,

On a webpage I have three comboboxes. The second and the third are
dynamically filled dependent from the choice in the first combobox.
Each choice in all three boxes consist of a numeric value and a
string. This is done through a javascript and it uses the numeric
values of the first box. When submitting the page to an asp script I
don't want to post these numeric values but the selected strings. Can
this be done???
You will only be able to see the values in the submitted data. So force the
value property or the options to contain the strings you want to post
instead of the numeric values. There is no requirement that the value
property has to be something different from the text property of the option.

Bob Barrows
 
D

Dave Anderson

Klaas said:
On a webpage I have three comboboxes. The second and the third are
dynamically filled dependent from the choice in the first combobox.
Each choice in all three boxes consist of a numeric value and a
string. This is done through a javascript and it uses the numeric
values of the first box. When submitting the page to an asp script I
don't want to post these numeric values but the selected strings. Can
this be done???

Let me first state that I would be inclined to get rid of the numbers
altogether. If you are not interested in them at submission, why bother
putting them into the document in the first place?

Back to your question. There are several ways to do this. Perhaps the most
straightforward is to change the value at submit:

option.value = option.text // [1],[2]

If your SELECT elements (they are not "comboboxes") are of the "select-one"
type [3], then it suffices to do it this way:

sel[sel.selectedIndex].value = sel[sel.selectedIndex].text

For "select-multiple" elements, you should iterate through the entire set of
option elements.

Please bear in mind that "option" and "sel" are object references,
representing something like
document.forms["myForm"].elements["mySelectElement"] and
document.forms["myForm"].elements["mySelectElement"], respectively.


[1]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/value_3.asp
[2]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/text_3.asp
[3]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/type_9.asp


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
K

Klaas Seelen

I have thought of that one too, the problem is I need the numeric values for
my javascript to dynamically fill te second and third box so I hope ther is
an other solution...

Klaas Seelen
 
B

Bob Barrows [MVP]

You have two choices:

Use client-side code (as suggested by Dave) to either either of these
actions on submit:
a. modify the selected option elements
b. populate hidden textboxes with the values of the selects


Use server-side code to retrieve the strings that correspond to the numeric
values from whatever source is used to provide the data for the "combos"
(note: there is no such thing as a "combo" in html - you have select
elements). Provide a little more info and we may be able to help you with
this.
 
K

Klaas Seelen

Thanks a lot, it worked...

Klaas Seelen

Dave Anderson said:
Klaas said:
On a webpage I have three comboboxes. The second and the third are
dynamically filled dependent from the choice in the first combobox.
Each choice in all three boxes consist of a numeric value and a
string. This is done through a javascript and it uses the numeric
values of the first box. When submitting the page to an asp script I
don't want to post these numeric values but the selected strings. Can
this be done???

Let me first state that I would be inclined to get rid of the numbers
altogether. If you are not interested in them at submission, why bother
putting them into the document in the first place?

Back to your question. There are several ways to do this. Perhaps the most
straightforward is to change the value at submit:

option.value = option.text // [1],[2]

If your SELECT elements (they are not "comboboxes") are of the
"select-one" type [3], then it suffices to do it this way:

sel[sel.selectedIndex].value = sel[sel.selectedIndex].text

For "select-multiple" elements, you should iterate through the entire set
of option elements.

Please bear in mind that "option" and "sel" are object references,
representing something like
document.forms["myForm"].elements["mySelectElement"] and
document.forms["myForm"].elements["mySelectElement"], respectively.


[1]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/value_3.asp
[2]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/text_3.asp
[3]
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/type_9.asp


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top