reload page based on combo box selection

If I have a combo box on my asp page, can I reload the page when a new item is selected from the combo box?  The page would load info from a database based on the selection made so I'm guessing I could somehow use the combo box selection as a url variable.

Thanks
LVL 18
mgcITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fritz_the_blankCommented:
Like this:

<select name="strYourSelect" onChange="this.form.submit()">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>

FtB

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mgcITAuthor Commented:
what would I put for the Form action so I can get the value of the selected item?

<form name="form1" method="post" action="????">

Thanks
fritz_the_blankCommented:
You can leave the action blank and the page will submit to itself. Alternatively, you can put the name of the page in there.

To grab the value of the selected item, just use: request.form("strYourSelect")


FtB
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

mgcITAuthor Commented:
ok I can get the form to submit when selecting an item from the combo box, but I can't get the value of the selected item to appear in the URL.  Here's what I have:

<form name="form1" method="post" action="CPEExpenseAccountMaster.asp?UserID=<%=Request.form("masterList")%>">
<select name="masterList" id="masterList" onChange="this.form.submit()">
<%while not(allUsers.EOF)%>
<option value="<%=allUsers("UserID")%>"<%if allUsers("UserID") = "MGC\"&Request("UserID") then response.write(" selected") end if%>><%=allUsers("UserID")%></option>
<%allUsers.MoveNext()%>
<%wend%>
</select>
</form>

when the page reloads this is the URL:

http://site/CPEExpenseAccountMaster.asp?UserID=

Thanks
mgcITAuthor Commented:
in case this is confusing, the "allUsers" variable is a recordset that contains user ID's stored in the DB...for instance:

jdoe
psmith
tjones

these names load correctly in the combo box (using the while loop) but when you select a different name from the list the url should have the user ID as a parameter such as:

http://site/CPEExpenseAccountMaster.asp?UserID=jdoe

hopefully that makes sense.  If you need more info just let me know.

Thanks
mgcITAuthor Commented:
Here's another update for you:

it seems like my code is *kind of* working.  If I make a selection from the combo box 2 times, it works - because it is grabbing the user ID that was selected previously - not the newly selected ID.
WoodyRoundUpCommented:
<form name="form1" method="post" action="CPEExpenseAccountMaster.asp%>">
<select name="masterList" id="masterList" onChange="this.form.submit()">
<%while not(allUsers.EOF)%>
<option value="<%=allUsers("UserID")%>"<%if allUsers("UserID") = "MGC\"&Request.form("masterList") then response.write(" selected") end if%>><%=allUsers("UserID")%></option>
<%allUsers.MoveNext()%>
<%wend%>
</select>
</form>
WoodyRoundUpCommented:
just helping out. :p
but it should be working fine.
fritz_the_blankCommented:
If you want it to appear in the URL, just use GET instead of POST on your form and you are done.

Alternatively, you can modify my script as follows:

onChange="this.form.action='yourpage.asp?parameter=' + this.options[this.selectedIndex].value;this.form.submit();"


FtB
mgcITAuthor Commented:
Thanks for the help!
fritz_the_blankCommented:
Glad to have helped,

FtB
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.