...

View Full Version : Auto fill textbox



rosehabib
02-27-2006, 07:35 AM
I have a form that includes 2 text input. I'd like the second text input to fill with the value selected from database based on the first textbox value, by default when the first text input loses focus. What methods should I look into to learn to do this?please help me as soon as possible....

GoComplain
02-27-2006, 11:37 AM
I think that sounds more like a javascript question

degsy
02-27-2006, 03:28 PM
Or you could use Ajax to pull info from the database. You would have to give more details about the script and database setup.

http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

degsy
02-27-2006, 03:52 PM
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="db.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = conn
Recordset1.Source = "SELECT user_name FROM ajax_user"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">

/***********************************************
* Dynamic Ajax Content- &#169; Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).value=page_request.responseText
}
</script>
<script type="text/javascript">
/***Combo Menu Load Ajax snippet**/
function ajaxcombo(selectobjID, loadarea){
var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
if (selectobj!="")
//alert('populate_form_getEmail.asp?name=' + selectobj.value + ', ' + loadarea)
ajaxpage('populate_form_getEmail.asp?name=' + selectobj.value, loadarea)
}
</script>
<style type="text/css">
<!--
.style2 {font-size: small}
-->
</style>
</head>

<body>
<form name="form1" method="post" action="">
<p>Name
<input name="name" type="text" id="name" onblur="ajaxcombo('name','email')">
(<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<%=(Recordset1.Fields.Item("user_name").Value)%>,
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
)
&lt;- Valid user names <br>
<span class="style2">*Type name then press tab to switch focus </span></p>
<p>Email
<input name="email" type="text" id="email" value="">
</p>
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>




<!--#include file="db.asp" -->
<%
Dim email__MMColParam
email__MMColParam = "1"
If (Request.QueryString("name") <> "") Then
email__MMColParam = Request.QueryString("name")
End If

Dim email
Dim email_numRows

Set email = Server.CreateObject("ADODB.Recordset")
email.ActiveConnection = conn
email.Source = "SELECT user_email FROM ajax_user WHERE user_name = '" + Replace(email__MMColParam, "'", "''") + "'"
email.CursorType = 0
email.CursorLocation = 2
email.LockType = 1
email.Open()

email_numRows = 0

If Not email.EOF Or Not email.BOF Then
Response.Write(email.Fields.Item("user_email").Value)
Else
Response.Write("")
End If ' end Not email.EOF Or NOT email.BOF

email.Close()
Set email = Nothing
%>

http://computer-helpforum.com/asp/ajax/populate_form.asp

rosehabib
03-02-2006, 10:25 AM
my database name:supplier_head
it contains:supplier_name, supplier_code

my asp form:
Supplier Code:
<input name="suppliercode" type="text" id="suppliercode">
Supplier Name:
<input type="text" id="textname" name="suppliername">

so, my actual problem is:
when i enter or key in the supplier code value, supplier name will appear at the next textbox (suppliername) which the value will be display based on value i enter on supplier code...

so, what is the best way can i do to make this thing happen...

degsy
03-02-2006, 03:07 PM
Just change the query to suit from the code I posted.

rosehabib
03-04-2006, 03:48 AM
i've tried your coding but its does not fullfill what actually i want.
actually, when i key in the supplier code, the supplier name will automatically be displayed based on the value of supplier code. there is no any submit button. just key in the supplier code and the supplier name display

degsy
03-06-2006, 03:02 PM
The code I posted is an example of the methods that you need to use.

You need to change the code to suit. It's obvisouly not going to work if you try to use that exact coding.

robr54
03-17-2006, 10:50 PM
Hi Degsy. Is the sample code that you provided all that I would need to make this work? What is the include for the db.asp? I checked out your sample page from the link provided and this will do exactly what I am looking for, I just need a little help with all of the pieces.

Thanks!
Rob

degsy
03-20-2006, 06:28 PM
The db file is just my external file for connecting to the database.

Once you have your connection made then the things that you need to change would be the queries and quesrystrings to extract the correct data.

degsy
03-20-2006, 07:30 PM
http://computer-helpforum.com/asp/aspfree/ajax_populate_form/ajax_populate_form.asp

See attachment for full coding.

flippy
03-30-2006, 11:35 PM
nevermind

Alidad
04-02-2006, 06:00 AM
Is there is way that we can write code in Visual basic! Is like click one button on IE toolbar then automatic fill in.

Does anyone have that information or know how to write that!

rosehabib
04-18-2006, 02:31 AM
Dim email__MMColParam
email__MMColParam = "1"
If (Request.QueryString("name") <> "") Then
email__MMColParam = Request.QueryString("name")
End If

Dim email
Dim email_numRows

Set email = Server.CreateObject("ADODB.Recordset")
email.ActiveConnection = conn
email.Source = "SELECT user_email FROM ajax_user WHERE user_name = '" + Replace(email__MMColParam, "'", "''") + "'"
email.CursorType = 0
email.CursorLocation = 2
email.LockType = 1
email.Open()

using the above code, you retrieve the user_email based on 1 condition that is user_name.what is the necessary code if I want to display the user_email based on 2 condition for example user_name and branch_name. The user only need to enter the user_name but it will compare both condition (user_name and branch_name)...

degsy
04-18-2006, 04:13 PM
Use standard SQL


sql="SELECT * FROM table WHERE field1 = '" & var1 & "' AND field2 = '" & var2 & "'"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum