Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically change Drop Down values 1

Status
Not open for further replies.

TudorSmith

Programmer
Jan 14, 2002
245
GB
Hi,

I have an ASP page linked to an SQLServer 2000 DB

On my page are two drop down boxes: Company & Site.

At the moment I'm using ADO to populate each DropDwon from a recordset.

What I want is to dynamically change DropDown No 2 to show only the sites relating to the selected Company in DropDown No1.

I've been trawling the web all morning looking for workable exambles but it's a little over my head (been developing ASP for 6 months).

If anyone has any examples or easy code to follow I'd appreciate it. I'm thinking Javascript and server side changes but I'm open to all suggestions.

Thanks

Tudor

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
what did the other sites tell u???

Known is handfull, Unknown is worldfull
 
They told me loads of useful information about Arrays. While this is good, they did not tell me how to populate the Array with a recordset in Javascript [sad]

If I can code it in Arrays that'll be fine...but it has to be dynamic since the data in the DB can change, and I won't be on site much longer to hold the clients hand (and change the code to suit new additionals to countries and sites)

So...I'm still looking... [upsidedown]

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
u have to combine javascript and asp to do this.
use asp to pupulate the select boxes and javascript to decide when the boxes must be populated.
e.g:
Dropdown1
Dropdown2

when the page loads for the fisrt time dropdown1 must be populated with data, dropdown2 must be left empty

now write this javascript:
<select name="dropdown1" onchange="resubmit()">

the js code is:
Code:
function resubmit()
{
 document.FormName.action="SamePage.asp"
 document.FormName.submit()
}

SampPage.asp is the fiel where the dropdowns are there.

Now when the form resubmits to itself u can read the value of Dropdown1 in SamePage.asp using the request method.

now that u have the value of DropDown1, go ahead and populate Dropdown2 with any sql.


do u get the idea???

Known is handfull, Unknown is worldfull
 
Hi,

I think we're getting there.

I put this script in my page, including a few alert to monitor progress:
Code:
<SCRIPT language="JavaScript">
function resubmit()
{
 alert("about to refresh")
 document.form1.action="TestPeriodDef.asp";
 alert("about to submit")
 document.form1.submit();
}
</SCRIPT>

Next I added the following:
Code:
<select name="SELECTCompany" id="select" style="width: 200px;" onchange="resubmit()">

Trouble is, the page is not refreshing. I'd know it if the page went blank and then reappeared right? It's just not doing that.

Have I got something wrong?



birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
remove the id part from ur select box and try.
this command - document.form1.submit(); is meant for resubmitting the form...

Known is handfull, Unknown is worldfull
 
Top Notch.

I wasn't sure abotu case sensitive entries, but changing the case helped. I now have a flash pair of drop downs which change accordingly!

thanks for the help...have a star

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
no probs...

Known is handfull, Unknown is worldfull
 
You should also take a look at the FAQs seciton, there are 3 (I think 3 at least :p) FAQs covering dynamic chained dropdowns, they may help give you to get another perspective on this which could prove helpful (or a complete waste of time, it's a toss up ;) )

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Perhaps this may hopefully give you some ideas. It's got a downloadable sample and does retain values after the post back:

Classic ASP Design Tips - Dependent Listboxes

J. Paul Schmidt, Classic ASP Web Designer
Classic ASP Design Tips, ASP Web Database Demo, ASP Bar Chart Tool...
 
Does your web server support remote scripting? If it does, you could provide a javascript that takes the selected item from dropdown1 and calls a db lookup function found in your remote scripting module. Pass the return values back to the javascript and fill the options in dropdown2 with the data. I do similar functions all the time. It really makes your client pages truly dynamic.

Jerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top