from Drop-down 2 text box in ASP?

AnakinVB
07-29-2002, 09:51 AM
Hello,
All I am trying to do is populate one-line text box from a selection box, upon clicking.
It is easy in VB6:
------------------------------------------
For j = 0 To List1.ListCount - 1

If List1.Selected(j) = True Then
txtItems.Text = CStr(List1.List(j))
End If
Next
End Sub
----------------------------------------------------
But it seems really tricky in ASP/VBScript.

1) If Rezner reads this, the javascript template you gave me:

onClick="yourFormName.yourTextbox.value=yourFormName.yourCombo.value";

calls for the form name, but when we created the controls we omitted the form tags altogether. How do I handle the form name when there isn't a form tag?

2) I have tried to integrate Javascript in the middle of ths page. the <%Language=JavaScript%>
How and when will the interpreter know to switch back to VB Script?


3) Here is my failed attempt:
--------------------------
<%


Set AnakinadoCon = Server.CreateObject("ADODB.Connection")

AnakinadoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("AnakinCars.mdb") & ";" & _
"PeRSist Security Info=False"

Set RS = Server.CreateObject("ADODB.Recordset")

RS.Open "SELECT carID, carName " & _
"FROM Cars ORDER BY carName", _
AnakinadoCon, 3, 3, 1

response.write "<SELECT" & "NAME =" & "AnakinCombo>"

While NOT RS.EOF
response.write _
"<OPTION VALUE=" & RS("carID") & ">" & RS("carName") & "</OPTION>"

onClick="AnakinText.value=AnakinCombo.value";

RS.Movenext
Wend
response.write "</SELECT>"
%>

<INPUT NAME = "AnakinText">

<%
While Not RS.EOF


RS.MoveNext
Wend
%>

</SELECT>

<%
'Close and destroy ADODB Recordset object
RS.Close
Set RS = Nothing

'Close and destroy ADODB Connection object
AnakinadoCon.Close
Set AnakinadoCon = Nothing

%>
----------------------------------

thx,
Jason

Rezner
07-29-2002, 10:26 AM
Notice the highlighted quotes. This is needed for car names that have spaces:<%
Set AnakinadoCon = Server.CreateObject("ADODB.Connection")

AnakinadoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("AnakinCars.mdb") & ";" & _
"PeRSist Security Info=False"

Set RS = Server.CreateObject("ADODB.Recordset")

RS.Open "SELECT carID, carName " & _
"FROM Cars ORDER BY carName", _
AnakinadoCon, 3, 3, 1
%>


<FORM NAME="f">

<SELECT NAME="AnakinCombo" onClick=f.AnakinText.value=f.AanakinCombo.value;>

<%
While NOT RS.EOF
response.write _
"<OPTION VALUE=""" & RS("carName") & """>" & RS("carName") & "</OPTION>"

RS.Movenext
Wend
%>
</SELECT>

<INPUT TYPE=TEXT NAME="AnakinText">
</FORM>


<%
'Close and destroy ADODB Recordset object
RS.Close
Set RS = Nothing

'Close and destroy ADODB Connection object
AnakinadoCon.Close
Set AnakinadoCon = Nothing
%>

Rezner
07-29-2002, 10:36 AM
Here's a better way of doing what you mentioned (for VB not ASP):For j = 0 To List1.ListCount - 1

If List1.Selected(j) = True Then
txtItems.Text = CStr(List1.List(j))
End If
Next For VB, the above code is overkill. Use something like this instead:
txtItems.Text = List1.List(List1.ListIndex)

AnakinVB
07-31-2002, 12:21 PM
I've been studying/working with the above ASP code for the past couple days. One line that I still don't see, although I suspect it may be easy is this:

........"FROM Cars ORDER BY carName", _
AnakinadoCon, 3, 3, 1

a) why does the top line end with just an underscore?
like this: _

b) While I think it has something to do with the Access table, I still haven't figured out the bottom line of the above code. I mean this particular code:

" AnakinadoCon, 3, 3, 1 "

I see that the first paramerter is the connection object, but what are the " 3,3,1 " ?

c) should I expect to use these parameters with RS.Open just about everytime I impart to a database. Or, are there lots of variations on these parameters?

Thx!

Rezner
07-31-2002, 04:09 PM
a) I do that mainly out of habit. Underscoring breaks a line of code up so it isn't one big chunk that causes you to scroll horizontally on the page. For example, compare the below two SQL statements. One is all on one line and one is broken up"SELECT [People].[LastName], [People].[FirstName], [Work].[StartDate] FROM [People], [Work] WHERE [People].[ID] = [Work].[PID] ORDER BY [People].[LastName];"

"SELECT [People].[LastName], [People].[FirstName], [Work].[StartDate] " & _
"FROM [People], [Work] " & _
"WHERE [People].[ID] = [Work].[PID] " & _
"ORDER BY [People].[LastName];"b) This is the CursorType, LockType, and Options for the new recordset. With "3,3,1" I'm simply referring to the enum indicies for each option instead of the actual enum string. For a detailed description of all these options, go here (http://www.devguru.com/Technologies/ado/quickref/recordset_open.html).

c) You're right though, there are lots of combinations. I typically use 3,3,1 for flexability and because it allows you to read an accurate Recordcount for the recordset.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum