View Full Version : Trying to populate a box based on an Access database value
willz06jw
06-15-2009, 03:12 PM
Thanks for your help,
I am going to describe my layout and then describe what i am trying to do -- I really don't even know if there is a way to do this.
Layout:
--------------------------------
Name Text box the user enters |
--------------------------------
-------------------------------- -----------------------
DeptCC Text box the user enters| |Find ConfirmDir Button|
-------------------------------- -----------------------
---------------------------------------------------------------
ConfirmDir text based on an Access data on same row as DeptCC|
---------------------------------------------------------------
-------------------
Submit Entire Form|
-------------------
Description:
What is the easiest way to have the page lookup the director in Access based on the DeptCC user entered text box --- and then be able to submit the whole form into another page.
Thanks for your help,
Will
Old Pedant
06-15-2009, 06:42 PM
Two choices:
(1) Submit the <form> to two different ASP pages, depending on whether or not that field is filled in. You can either change the ACTION= of the <FORM> in the ASP code or using JavaScript.
(2) Use AJAX to fill in the extra field.
Okay, a third way:
(3) Use an IFRAME. (If you don't mind putting the extra field in an <iframe> then you could just submit the info to and ASP page that returns just enough data to fill the iframe.)
Most people nowadays would opt for (2), but that's entirely up to you. Any of the 3 would work.
willz06jw
06-15-2009, 08:48 PM
My company still uses IE6 with ActiveX off --- Can I still use AJAX?
Old Pedant
06-15-2009, 09:12 PM
Dunno... I don't know if the Microsoft.XMLHTTP object in JavaScript is considered to be ActiveX or not. Wouldn't bet against it. But would be easy enough to try it out.
But you could surely use a hidden IFRAME, if worst comes to worst. I was doing that in 1999 before we had AJAX, and it worked well.
Example:
<form name="MainForm" method="post" action="whatever.asp">
<input name="theName">
<input name="DeptCC"
onchange="document.getElementById('HIDE').src='getDir.asp?deptcc='+this.form.DeptCC.value;">
<input name="Director" readonly>
...
<input type=submit>
</form>
...
<iframe id="HIDE" style="display: none;"></iframe>
...
And then your getDir.asp code looks like this:
<%
deptcc = Replace(Trim(request("deptcc")),"'","''")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...."
Set rs = conn.Execute("SELECT Director FROM yourtable WHERE deptcc='" & deptcc & "'"
director = "[not found]"
If Not rs.EOF Then director = rs(0);
rs.Close
conn.Close
%>
<script>
window.parent.document.MainForm.Director.value = "<%=director%>";
Presto.
You see how it works?
Old Pedant
06-15-2009, 09:13 PM
Heh! And that's actually much simpler and less code than AJAX would be, anyway.
willz06jw
06-16-2009, 10:09 PM
My god it works! Thanks for your help.
Will
BTW: I think
deptcc = Replace(Trim(request("deptcc")),"'","''")
should read
deptcc = Replace(Trim(request.QueryString("deptcc")),"'","''")
Thanks again for your help!
Will
Old Pedant
06-17-2009, 12:14 AM
Nah...when you use REQUEST("xxx") it *automatically* checks *all* the request collections looking for "xxx". It does them in a certain order:
Request.QueryString
Request.Form
Request.Cookies
Request.ServerVariables
Request.ClientCertificate
.
So if you are using Request("xxx") when you know that it's actually Request.QueryString("xxx"), you are actually saving a few nanoseconds, just because the extra token (the [i].QueryString) takes longer to process than for ASP to do the automatic search. And, actually, it's a tossup for Request.Form vs. just Request.
I tend to *ALWAYS* use just Request("xxx") because I like to start with <form method="get"> so that I can see exactly what is being passed to the next page by just looking in the address bar. Then, after the page is working, I just change to method="post" and I don't have to change my ASP code at all.
willz06jw
06-18-2009, 02:47 PM
Correct again! I learn something everyday. Thanks for your help
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.