|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
multiple drop downs in a form
ok .. basically what im trying to do is create a form to submit some data to an access db.
In the form i want to be able to have two dynamically populated drop downs (so if a user chooses cars in the first field it comes up with a bunch of car manufacturers, or if he chooses boats it comes up with boat builders etc etc.) Ive searched high and low, and i the best i can find is javascript to make the drop dows. The java script however uses a form to repost the data back to the page to populate the second drop down. This wont work when its inside a form. So my question is, can this be done? and if so how? id appreciate any help i can get |
|
#2
|
|||
|
|||
|
URL
|
|
#3
|
|||
|
|||
|
thats kinda what i wanted.. but i was hoping for something that i could populate from a database
thanks for the quick reply .. i think im at the stage where i might just have to use this sort of script |
|
#4
|
|||
|
|||
|
I load my combos using a javascript and XML dynamically. *No page refresh.* But it needs two files. There could be a little bit of maintanace hassle due to the large number of files.
One is your interface file and the other that fetches the data in XML format. I have already given that out in this forum. I can show you how to if you are interested. -aspman
__________________
If you ask a question you are a fool for a second. But if you dont ask, you are a fool for a life time. |
|
#5
|
|||
|
|||
|
aspman... that would be great
where abouts did you post it so i can go check it all out?? |
|
#6
|
|||
|
|||
|
I could not find the post. I would repost it for your convenience.
here is what it looks like in the client. Code:
function populateCombo() {
var cbopad = 0;
if(form.combo1.value > 0) {
XMLDataisland.async = false;
XMLDataisland.SRC = "/<%=approot%>/data/yourpagewithxmloutput.asp?id=" + value;
var vals = XMLDataisland.getElementsByTagName("z:row");
if(vals.length > 0) {
if(vals.length > 1) {
form.combo2.options[0] = new Option("-Select One-",0);
cbopad = 1;
}
for(var i=0; i < vals.length; i++) {
form.combo2.options[i+cbopad] = new Option(vals.item(i).attributes(1).text , vals.item(i).attributes(0).text);
}
} else {
form.combo2.options[0] = new Option("N/A ",0);
}
}
}
and in your body section of the html/asp page Code:
<XML ID="XMLDATAISLAND"></XML> as far as the server page is concerned here is what you need to do inorder to get the recordset as an xml string Code:
function getXMLstr(strSQL, cnn)
on error resume next
dim oStr, oRS, oCon, strConn, oops
Response.Write("<?xml version='1.0'?>" & vbCrLf)
set oCon = getConnection(cn)
set oRS = server.CreateObject("ADODB.Recordset")
oRS.Open strSQL, oCon
set oStr = Server.CreateObject("ADODB.Stream")
oStr.Open
oRS.Save oStr, 1
if err.number = 0 then
getXMLData = oStr.ReadText
else
err = "<xml>"
err = err & "<error>Query Execution failed. Check your connection parameters and query .</error>"
err = err & "</xml>"
getXMLData = err
end if
oStr.Close
set oStr = nothing
oRS.Close
set oRS = nothing
end function
Pass the sql query and connection to this function Code:
sqlstring="select * from foo" response.write getxmlstr(sqlstring,connectionstring) you should be all set |
|
#7
|
|||
|
|||
|
thanks for that .. ill see what i cant break =)
|
|
#8
|
|||
|
|||
|
sorry to hassle you aspman, but ive given it a shot and i dont really know what im doing. I dont really know enough about all this to make it work. Whats started off as a simple thing has now gone past what i know.
Do you think you could tell me what pages what goes on and where i put the combo boxes etc. im confused as hell and dont know what im doing now |
|
#9
|
|||
|
|||
|
it'd be easiest just to refresh the page
is there anything that's limiting you from that? |
|
#10
|
|||
|
|||
|
how do you mean refresh the page??
how will that populate a second drop down?? this is alot more complex than origianlly though |
|
#11
|
|||
|
|||
|
check this out, you put on onchange='myform.submit();' in the drop down box. Once it submits you do your queries like usual for the first drop down right? Then for the second one, request.form("dropdown1") will have a value, you query the db for select * from table where column = ' request.form("dd1")' and bam, that's the recordset you populate the second drop down menu with, it's really that easy, just awkward at first.
|
|
#12
|
|||
|
|||
|
unatratnag, as i said before, im really getting out of my depth here, this is getting past what i know, is there any chance of you giving me a working demo of this or pointing me to it .. i really am struggling to get my head around this at the moment *bangs head on desk*
thanks for the help |
|
#13
|
|||
|
|||
|
well, you have two drop downs right, for the second one you have to query the database where you say "SELECT * from TABLE", now you just add this before the querystring
Code:
strSQL = "SELECT * from TABLE"
if request.form("nameofdropdown1") <> "" then
strSQL = strSQL & " WHERE type = '" & request.form("nameofdropdown1") & "'"
end if
and that's all you have to change for the query. in drop down box one you say Code:
<select onchange="nameofyourform.submit();"> and that's it for autosubmitting for drop down 1, you can do the same thing for the other drop down if the user selects that one first. |
|
#14
|
|||
|
|||
|
Why make the unecessary round trips to the server using asp? As long as the data is static (not changing) trying using javascript.
daniel |
|
#15
|
|||
|
|||
|
Why make the unecessary round trips to the server using asp? As long as the data is static (not changing) trying using javascript.
daniel |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > multiple drop downs in a form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|