|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic Drop Down Boxes And Form Variables Retainment
Hi To All,
I was hoping that someone could help me out. Here's my problem. I have two drop down boxes. Both need to be populated from a database. dpd_box1 dpd_box2 When I select something from dpd_box1 I need dpd_box2 to re-populate itself from a database. I then need to retain all the other values that have been put into some other fields on the form. For an example I was going to use something like: Database Name: Temp_Database Table Name One: tbl_dropdown1 #dpd_id dpd_name Table Name Two: tbl_dropdown2 #dpd_id dpd_no dpd_name So there is a link between dpd_id and dpd_no. I hope I have provided enough information. Thanks for all your help |
|
#2
|
|||
|
|||
|
If you look at the bottom of your thread, you'll notice a place that says:
More Related threads The answer was right under *your* nose! Have a look here... http://forums.devshed.com/t65760/s.html Hope this helps! Sincerely Vlince |
|
#3
|
|||
|
|||
|
Hi Vlince
I had a play around but still cannot get it to work. Excuse me, but i'm very new to asp and have never used javascript before. It would be much appreciated if you could outline an example with my particular database. Thanks for your time. Kind Regards |
|
#4
|
|||
|
|||
|
THEORY:
in the combo box 1, onchange call document.myform.submit(); then when populating the combo boxes, if the request.form("combobox1") is equal to some value, you set it equal to that again by default, and you query the DB for table 2 where primkey = comobox1. example combobox 1 has: car motorcycle boat when i select boat, the form resubmits it self when populating combobox 1 since request.form("combobox1") has a value, i write selected under the appropriate combobox, boat. then comes combo box 2, since combo box 1 has a value, you query the DB and select * from models where type = ' request.form("combobox1")' and then you have all your second combobox2 values, and then you jsut populate it that way. the trick is at the top of the page, you do a check for request.form("submit"), assuming you're calling your submit button submit, if it's <> "", then the user has clicked submit. This works since if it's = "", this is the first time visiting the page or it was force submitted by javascript. If it's <>"" you do whatever else you need your form to do and move on etc etc... it's key you understand what you're doing before you fumble around trying to just get it work. |
|
#5
|
|||
|
|||
|
Thanks for the quick reply.
do you have some example code that i could perhaps look at. thanks |
|
#6
|
|||
|
|||
|
please understand what you're doing first
Javascript Code:
function refresh()
{
//alert ("HELLO");
document.myform.submit();
}
top of page Code:
if request.form("Update") = "Update" then
Do update stuff here
response.redirect "updated.asp"
end if
<select name="D1" onchange="refresh();">
<option value=""></option>
strSQL = "select (requestNumber) as rn, ContactFullName as fn, dateRequested as dr, presenters as pr, " & _
"webcastName as wn from request_received order by rn desc"
set RS = objConn.Execute(strSQL)
'-----------the first selection box
RS.MoveFirst
do while not RS.EOF
response.write "<option "
if request.form("D1") <> "" then
if Cint(request.form("D1")) = RS("rn") then
response.write "selected"
end if
end if
response.write " value=""" & RS("rn") & """>"
Response.Write "Webcast Number: " & RS("rn")
Response.write ", Requester: " & RS("fn")
Response.write ", Webcast Name: " & RS("wn")
response.write "</option>"
RS.MoveNext
loop
autofilling in selection boxes Code:
Please provide the following contact information:</P>
<%
strSQL="select * from [request_received] where requestnumber = '" & request.form("D1") & "'"
set RS = Conn.Execute(strSQL)
'response.write "D1: " & request.form("D1") & "<br>"
%>
<TABLE>
<TR>
<TD ALIGN="right">
<EM>Name</EM></TD>
<TD>
<INPUT NAME="Contact_FullName" SIZE=35 <% if request.form("D1") <> "" then response.write "value="""&RS("ContactFullName")&"""" end if%>">
</TD>
</TR>
<TR>
<TD ALIGN="right">
<em>Quicklook ID</em></TD>
<TD>
<input type="text" name="quicklook" size="35" maxlength="8" onBlur="emailFill();" <% if request.form("D1") <> "" then response.write "value="""&RS("quicklook")&"""" end if%>></TD>
</TR>
<TR>
<TD ALIGN="right">
<EM>Organization</EM></TD>
<TD>
<select size="1" name="Contact_Organization">
<option>Choose Option</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "CFO" then response.write "SELECTED" end if end if%>>CFO</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Chief Marketing Officer" then response.write "SELECTED" end if end if%>>Chief Marketing Officer</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Corporate Public Relations" then response.write "SELECTED" end if end if%>>Corporate Public Relations</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Financial Solutions Division" then response.write "SELECTED" end if end if%>>Financial Solutions Division</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Global Procurement" then response.write "SELECTED" end if end if%>>Global Procurement</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Human Resources" then response.write "SELECTED" end if end if%>>Human Resources</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "IT Services" then response.write "SELECTED" end if end if%>>IT Services</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Law" then response.write "SELECTED" end if end if%>>Law</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Quality" then response.write "SELECTED" end if end if%>>Quality</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Retail Solutions Division" then response.write "SELECTED" end if end if%>>Retail Solutions Division</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Systemedia Division" then response.write "SELECTED" end if end if%>>Systemedia Division</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "Teradata Division" then response.write "SELECTED" end if end if%>>Teradata Division</option>
<option <% if request.form("D1") <> "" then if RS("ContactOrganization") = "World Wide Customer Services Division" then response.write "SELECTED" end if end if %>>World Wide Customer Services Division</option>
</select>
</TD>
that's the theory. There are things they i don't check like if it's already rs.eof first but like i said, my environment is different then yours. Last edited by unatratnag : September 9th, 2003 at 07:16 PM. |
|
#7
|
|||
|
|||
|
and i hope you appreciate that, i had to boot up my work pc which quite frankly scares me if i'm not working =(
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Dynamic Drop Down Boxes And Form Variables Retainment |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|