Forum Moderators: open

Message Too Old, No Replies

ASP-Database

search Access when user leaves textbox

         

Unicorn

12:18 pm on Sep 24, 2003 (gmt 0)

10+ Year Member



Hi all,
I have a textbox on a ASP page and when the user enters a code, like q23 say, a Javascript is called within the page that converts it to capitals, ok easy enough, the user now sees Q23 in the textbox he has just left. This done with the code ...onchange="MakeUpper(this)".....within the input type tags<>. Now I need the same javascript or other method to automatically open a database (Access) without the user having to click or do anything else, and once the code has been found in a field on a row of a table, to return the text in another field of the row and print it out on the users web page beside the textbox.This textbox is part of a table on the web page, so the found text needs to go into the next <td> of the <tr>..ok, I can open and read etc a databse via ASP when a user clicks something but how to u get these two things (the capitalising & reading a DB) done automatically just by the user leaving a input text box?....any help or pointers please.

BlobFisk

12:41 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, Unicorn!

You are going to need to, at least, refresh the page - this cannot be done within a single document.

In order to begin the database query, you are going to need to run some server side script, and in order to do this you need to send a request to the server by going to another (or the same) ASP page.

Unicorn

1:31 pm on Sep 24, 2003 (gmt 0)

10+ Year Member



ok, thanks for the welcome ...right, how do I call another ASP page automatically with the javascript that capitalises the user input.?....
I'm using...

<script language="javaScript">
<!--
function MakeUpper(i)
{
i.value = i.value.toUpperCase();
}
//-->
</script>

and then do I add

return;

as the last line under the new call to the other ASP Page in this function?...>>

BlobFisk

1:50 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are going to need to submit data to the page (the value), so you will need to submit the form:

document.formName.submit();

HTH

Iguana

2:02 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



3 Options

1. Preload a javascript array with the reference data and populate the <td> on inputbox.onBlur()

2. There is a remote scripting option - your javascript opens up an invisible IFrame and the IFrame content is an ASP page that extracts the data from the database and calls a function back on the original page to do whatever you want with the data - this does work but you need to really know what you are doing (search for 'remote scripting iframe' on Google and take the top search result for some example code)

3. Stop trying to reproduce desktop apps/functionality on a web application. The programming methods are different and the design should be different from the desktop. Of course, the people who ask (and pay) for these apps don't listen to this arguement so you end up giving them slower/more flaky code in an attempt to reproduce the desktop.

Unicorn

2:13 pm on Sep 24, 2003 (gmt 0)

10+ Year Member



ok..sorry to appear thick BlobFisk, but I now have the function on my form as....

</style>
<script language="javaScript">
<!--
function MakeUpper(i)
{
i.value = i.value.toUpperCase();
document.WPQTT.submit();
}
//-->
</script>

the WPQTT is the name of the current form which has this script in it....I get an error "object doesn't support this property or method" on the document word in the script.

Where do I reference the extra ASP page and how do I forward the value in a var with that submit line?..>>>

Unicorn

8:04 am on Sep 25, 2003 (gmt 0)

10+ Year Member



ok , fixed the error message, ..had the wrong DOCTYPE on the form....>>

Unicorn

8:38 am on Sep 25, 2003 (gmt 0)

10+ Year Member



I'm looking at the Iframe suggestion...many thanks Iguana.>>>

Unicorn

10:46 am on Oct 8, 2003 (gmt 0)

10+ Year Member



Having no luck with IFRAMES.....It will not run any ASP code ..i.e. the ASP code in the ASP Page which is sent to the IFRAME by a Javascript in my starting page will not run ...am hitting my head against brick wall here...any help out there?..>>

BlobFisk

11:03 am on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




the ASP code in the ASP Page which is sent to the IFRAME by a Javascript in my starting page will not run

How are you submitting to the iFrame?

Unicorn

11:23 am on Oct 8, 2003 (gmt 0)

10+ Year Member



Hi BlobFisk, thanks for the contact again.....

I'm using code i found searching the web... its..

<SCRIPT LANGUAGE="JAVASCRIPT" src="exchanger.js"></SCRIPT>
<SCRIPT LANGUAGE="JAVASCRIPT">

var theBuffer;

//call this function in page onload event handler
function initialize()
{
theBuffer = new exchanger("myframe");
}

//call this function when data needs to be sent to server
function sendDataToServer(data)
{
theBuffer.sendData("rx.asp?" + data);
}

//call this function to check what the server returns.
function showReturnData()
{
document.all("1").innerText = ' '+ theBuffer.retrieveData("myNewData");
}

</SCRIPT>

</head>

<Body onload="initialize()">
<IFRAME name=myframe style="width:4000;height:200"></IFRAME>

<script type="text/javaScript">
function MakeUpper(i)
{
i.value = i.value.toUpperCase();
var test =i.value;
sendDataToServer("data="+test);
}
</script>

and the exchjanger script is...

function UserAgent()
{
var b=navigator.appName.toUpperCase();

if (b=="NETSCAPE") this.b="ns";
else if (b=="MICROSOFT INTERNET EXPLORER") this.b="ie";
else if (b=="OPERA") this.b="op";
else this.b=b;

this.version=navigator.appVersion;
this.v=parseInt(this.version);

this.ns=(this.b=="ns" && this.v>=4);
this.ns4=(this.b=="ns" && this.v==4);
this.ns5=(this.b=="ns" && this.v==5);

this.ie=(this.b=="ie" && this.v>=4);
this.ie4=(this.version.indexOf('MSIE 4')>0);
this.ie5=(this.version.indexOf('MSIE 5')>0);
this.ie55=(this.version.indexOf('MSIE 5.5')>0);
this.ie6=(this.version.indexOf('MSIE 6')>0);

this.op = (this.b=="op");
this.op4 = (this.b=="op" && this.v==4);
this.op5 = (this.b=="op" && this.v==5);
}

at=new UserAgent();

//if you want to create the frame or layer dynamically, do not
//specify a name, do something like this, new exchanger();

function exchanger(name)
{
//hold the dynamically created iframe or layer
this.lyr = null;

//to remember if the iframe or layer is created dynamically.
this.isDynamic = false;

this.name=name¦¦"";
//this.fakeid=0;

if (name == null ¦¦ name=="")
{
this.isDynamic = true;
this.create();
}
else
{
this.name=name;
if (at.ns4)
{
this.lyr = window.document.layers[this.name];
}
}
}

//this function should not be called directly
exchanger.prototype.create=function()
{
if (at.ns4)
{
this.lyr=new Layer(0);
this.visibility = "hide";
}
else if (at.ie ¦¦ at.ns5)
{
this.lyr=document.createElement("IFRAME");
this.lyr.width=0;
this.lyr.height=0;
this.lyr.marginWidth=0;
this.lyr.marginHeight=0;
this.lyr.frameBorder=0;
this.lyr.style.visibility="hidden";
this.lyr.style.position="absolute";
this.lyr.src="";
this.name="tongIFrame"+window.frames.length;
//this will make IE work.
this.lyr.setAttribute("id",this.name);
//this will make netscape work.
this.lyr.setAttribute("name",this.name);
document.body.appendChild(this.lyr);
}
}

exchanger.prototype.sendData=function(url)
{
//this.fakeid += 1;
var newurl = "";
if (url.indexOf("?") >= 0)
newurl = url
// + "&fakeId" + this.fakeid;
else
newurl = url
// + "?fakeId" + this.fakeid;

if (this.isDynamic¦¦at.ns4)
this.lyr.src=newurl;
else
{
if (at.ie ¦¦ at.ns5 ¦¦ at.op)
{
window.frames[this.name].document.location.replace(newurl);
}
}
}

exchanger.prototype.retrieveData=function(varName)
{
if (at.ns4)
{
return eval("this.lyr." + varName);
}
else if (at.ie ¦¦ at.ns5 ¦¦ at.op)
{
return eval("window.frames['" + this.name + "']." + varName);
}
}

and my RX.ASP is...

<%response.buffer=true%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
<!--Program design started 14th January 2003-->
<html>
<head>
<!--#include file="adovbs.inc"-->
<meta http-equiv="content-type" content="text/html;charset=windows-1252" />
<title></title>
</head>
<body>
<script language="javascript">
myNewData = '<%=request.querystring("data")%>';
</script>
<%
Set ConnDB = Server.CreateObject("ADODB.Connection")
ConnDB.Open "ShepNims"
Set ShepRS = Server.CreateObject("ADODB.Recordset")
Query ="SELECT * FROM QTT WHERE ItemCode=N68"
ShepRS.Open Query,ConnDB,adOpenStatic, adLockOptimistic

myNewData = ShepRS("Description")
ConnDB.close
Set ShepRS = Nothing
Set ConnDB = Nothing
%>

<table border="1">
<tr><td><%=nyNewData%></td></tr></table>

<script language="javascript">
window.parent.showReturnData(myNewData);
</script>

</body>
</html>

sorry theres so much code here, hope u can pick out the necessary bits......>>

txbakers

11:51 am on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



your code is way to complicated.

set the action of your form to the same page.

in your onChange (or onBlur) method, make uppers, then submit the form.

Process your read, and show the page back with the database data.

You'll need something like this is the ASP section:
query = false
if cstr(Request.Form("submit")) <> "undefined" then
run query
query = true
end if

Then, down below hide the rows with DB data using the boolean variable.

Unicorn

12:08 pm on Oct 8, 2003 (gmt 0)

10+ Year Member



ok, will go and try that.....many tks....cul....>>

Unicorn

12:20 pm on Oct 8, 2003 (gmt 0)

10+ Year Member



ok TxBakers., ur idea is reloading the page from the server with the new data in place, and thats ok but i was looking for a workround which didnt submit the page or reload it , because I have potentially twenty of these refreshes before the user is finished with the page and the data he submits is stored in a database. I was looking at the IFRAME method to dend stuff in the background to/from the server but cant get the ASP to run on the server by this method..All my other ASP does run ok when submitted with the submit button, just this task of filling in a TD of a table with text from a DB depending on the data entered in a text field wiothout reloading the page in between him/her filling out the form.

BlobFisk

1:11 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems like you are looking for an equivalent of target= on your form action?

Unicorn

1:31 pm on Oct 8, 2003 (gmt 0)

10+ Year Member



OK BlobFisk....the error message I'm getting on the IFRAME itself is....

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/Shepwww/rx.asp, line 17

and this is the ASP code which opens the DB and looks for the inputted text in a tabl field...my code to do this works fine on every other ASP Page it is....

<%
set ConnDB = Server.CreateObject("ADODB.Connection")
ConnDB.Open "ShepNims"
set ShepRS = Server.CreateObject("ADODB.Recordset")
query="SELECT * FROM QTT WHERE ItemCode=N68"
ShepRS.Open query,ConnDB,adOpenStatic, adLockOptimistic
myNewData=ShepRS("description")

ConnDB.close
Set ShepRS = Nothing
Set ConnDB = Nothing

%>

where I'm just trying to get it to run by using N68 embedded in this code..this will be the variable containing the user input...on ur point of a target......would this be the target for the RX.ASP form sent to the IFRAME or the target of the hoem ASP page which the user is filling in...its ' action=' is to itself.....>>>

txbakers

3:32 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the difference between pinging your server in an iFrame for every DB request, and just refreshing the page every time? You're still sending a SQL request to the server every time.

Why make it more complicated for yourself and the user? Keep it simple and functional and your users will hug you.

BlobFisk

4:40 pm on Oct 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree with txbakers - I think that you are getting into a world of pain by adding layer (or in this case, frame ;) ) upon layer complication...

The KISS rule has saved many a grey hair!

Unicorn

6:41 am on Oct 9, 2003 (gmt 0)

10+ Year Member



ok chaps......i give in!.......I've spent too much time on this particular point so I'll move on ....it takes a few other people to show some there errors ...again many thanks for the input....I'll be back (to quote a phrase) no doubt with another pointless exercise....>>