Click to See Complete Forum and Search --> : passing values from one text box to another
raineel
03-14-2006, 01:43 AM
hi all,
i have a database in sql server 2000 with multiple tables. i have a form with 3 text boxes. i wanted to know how to go about when one enters and id number in the 1st text box and once he tabs out of the box the 2nd and 3rd text boxes get populated with the first name and last name of the person who entered the id. the id comes from table id and the first name and last name comes from tbl data. i wrote appropriate select statments, but do not know know how to call these statements in my asp page.
any help is appreciated.
thankyou in advance
raineel
Since ASP is a Server Side language, you would not be able to populate the 2nd and 3rd fields without refreshing the browser.
chrismartz
03-14-2006, 09:12 PM
I recommend looking in the javascript forum to be able to do this.
lmf232s
03-15-2006, 04:10 PM
Well im not so sure javascript is the way to go here. Let say you were dealing w/ 1000 users, you would have to load all those names into some kind of an array and then look it up.
Instead i would do this w/ asp and once the user has entered the id ( ok, i would use javascript to submit the page), i would have the page submit back to its self and do the look up of the name based on the id and then populate those two fields.
Here is an example, it might be a tad bit confussing on how i set up the page but i do this so my asp pages are more object oriented like. Kind of.
Let me try to explain how this works.
I have a hidden field named hidsubmit.
This field holds the value of what i want to do.
So when i call the javascript function i populate this hidden field w/ LookUpById.
Now when the page submits, i request the value of hidsubmit.
Then i have the select case. Everything is done in the select case.
The case "LookUpById" is the section that will be executed. In this section
ill look up the first and last name and set the textbox variables = to those
values.
now then the page is loaded, it will have all 3 textboxes populated (given taht the id was a valid id and it returned something. Else you should display some kind of err message.
It might seem a little confussing but this is how i code my pages. This way its more like VB where i can execute a certian chunck of code w/ say a particular button click, etc............
Hope this helps.
<%
option explicit
Dim sSQL
Dim txtText1 : Request.Form("txtText1")
Dim txtText2
Dim txtText3
Dim hidsubmit : hidsubmit = Request.Form("hidsubmit")
Select Case hidsubmit
Case "LookUpById"
oConn_Open()
sSQL = "SELECT * FROM TABLE WHERE ID = '" & txtText1 & "'"
set oRS1 = oConn.Execute(sSQL)
If Not oRS1.EOF then
txtText2 = oRS1("Value1")
txtText3 = oRS1("Value2")
End If
oConn_Close()
Case Else
'not doing much in here for this example
End Select
%>
<head>
<script language=javascript>
function GetName(){
document.LookUpExp.hidsubmit.value = 'LookUpById';
document.LookUpExp.submit();
}
</script>
</head>
<body>
<form name=LookUpExp method=post>
<input type=hidden name=hidsubmit value="">
<input type=text name=txtText1 value="<%=txtText1%>" onBlur="GetName();"><br>
<input type=text name=txtText2 value="<%=txtText2%>"><br>
<input type=text name=txtText3 value="<%=txtText3%>"><br>
</form>
</body>