View Full Version : populate txtfield using record ID from value of select box

10-28-2004, 06:35 PM
Hi, I'm using ASP to pull in a recordset and populate a select box.:

my table for the recordset looks like this:

OptionId OptionName OPtionPrice

the Select box is populated as follows:

value = optionID, title = OPtionName

When the user selects an OptionName, I need to somehow, re-query the recordset (or by whatever other means you guys suggest) and find the correct price.. Then I shove that price into the textfield.

One 'hack' would be to simply have the optionprice as the value of the list boxes and push that into the txtfield on change.. but that's no good as when the form is submitted, I need that OPtionId value to do some other stuff.

I know ASP back to front, but Javascript?? I'm pretty bad.

Can anyone point me in the right direction?



Roy Sinclair
10-28-2004, 07:14 PM
Actually you need two value fields, one to hold the optionID and one to hold the OptionPrice. The nice thing is that you can use the one field provided as if it were two separate fields by using a delimiter character (pick a character that won't be in the text of either field). Then when an option is picked and you get the value of the option you can then use the javascript split function to make that value into it's discrete parts, displaying the price.

When the form is submitted you can parse the submitted value to extract just the optionID part.

10-29-2004, 10:46 AM
bever thought of that

however I am struggling a little with the split function for javascript.

I know how it works in ASP, but not sure of my code for javascript:
here's my simple code for now.



Roy Sinclair
10-29-2004, 05:00 PM
Assuming you use "~" as your separator character and the price is the first field then you'd do something like:

onchange="var ss,sa; ss=formName.selectListName[formName.selectLi
stName.selectedIndex].value; sa=ss.split('~'); formName.fieldName.value=sa[0];return true;"