...

View Full Version : ComboBox Item Populating a Form



Abd
04-23-2003, 06:42 PM
Hi All,

I pls need a help, may be a sample code or something on, I want to be able to search a user with a user code, get a form populate if the user exist in the Database, but at the same time in one corner of the form I want to be able to see the list of other user's code in a ComboBox from the Database, and onclicking on any user code in the ComboBox the same form should be populated with the user' information.

Right now I have a functional Application but without the ComboBox functionality.

Thanks

Abdul

raf
04-23-2003, 07:55 PM
Whats the problem? Building the combobox or the onclick submit or ???

Abd
04-24-2003, 08:40 AM
raf,

not Building the ComboBox, I can build a ComboBox that will get populated with a database data, BUT the problem is I want onclicking any usercode or item in the ComboBox it should populate the same Form where the ComboBox appear, do you get my point?

Abdul

raf
04-24-2003, 09:40 AM
I see. I posted some code for a similar problem here
http://www.codingforums.com/showthread.php?s=&threadid=15258&highlight=populate
look for the post of me on 03-03-2003 (9.20 h)

The code build a dropdown, and on submit, posts to itself and loads the same page with an additional dropdown. It's basically the same mechanisme then for your problem. You need to build a mutipurpose page. The first time the page is loaded, the dropdown is created and shown. If you submit the form (after choosing an option from the dropdown) the script checks if there is a value for the dropdown in the form-colection. If there is one, the sql statement to select the info is ran and is shown. (just as the dropdown) If you pick another option from the dropdown, a new select will be made etc etc.

So it's basically just adding a condition on top of the page and put the code to generate the dropdown and to pupulate the form together. Like:

if Len(request.form("dropdownname")) = 0 then
your code to build and display dropdown
(in the select tag, you need an onclick="submit();", and the method="post" and name="pagename"
else
your code to build and display the dropdown + perhaps set the picked value as selected
your code to select the info and display it
end if

But i wouldn't do that. For starters, if you want the dropdown in the same form, you need to recreate it each time they pick another option! So this means a call to the webserver, a call to the db, looping through the recordset, building the dropdown. So this means a lott of overhead and tranfic.
If you have an onclick, you'll also have some 'false-hits' which means useless trafic.

So, i'd suggest working with a framepage. Have the dropdown in the left/right/top frame and load the info in another framepage. The code will be even easier, since the if then else can be dropped, there be less trafic and quicker responsetimes. (The dropdown just stays visible in one of the framepages, with the picked option selected)

Abd
04-24-2003, 11:32 AM
raf,

pls I will need more detail on you

-----------------------------------------------------------
in the select tag, you need an onclick="submit();", and the method="post" and name="pagename
----------------------------------------------------------------

can you help with the submit() function I mean the (code).

Thanks
Abdul

raf
04-24-2003, 12:58 PM
Your right. This wasn't one of my clearest posts. Your code should look something like this:


<form name="FormName" action="pages.asp" method="post">
<select name="catagory" size="1" onclick="submit();">

First line = openingtag form. Second line: openingtag for the dropdownbox, with the javascriptcommand in it
You need to replace the "pages.asp" en "catagory" with your pagename and name of the dropdownbox

But it'd advice agains working this way (see previous post)

If you use a frameset, you need to set the tartget in the form tag
<form name="FormName" action="pages.asp" target="name of frame where to load the file" method="post">

Abd
04-24-2003, 01:31 PM
thanks raf,

I understand that;


<script language="JavaScript">
function Submit()
{
.
.
.
.


}

but what I mean is what type code will be inside Submit()?

Abd

raf
04-24-2003, 02:22 PM
I understand that;
No you don't :D Just try it like that. No extra code needed. It's magic ! Just
<select name="catagory" size="1" onclick="submit();">
But you'll see why this is not a good way to work. Actually, you should click on the arrow in the dropdown, hold the mouskey down, go to the value and then release it. otherwise, if you releas the mousebutton, the form will be submitted before you select a value by clicking on it. So you'll always have false hits etc. You can probably use doubleclick to submit, but then you'd have to write a small instruction near the dropdown etc, so it then would be easier to just add a submitutton or an arraw or whatever.

Abd
04-24-2003, 03:35 PM
raf,

Thanks for your patience, I have attached the frame screen with this thread, what am triyng to say briefly is

1. select a number from the ComboBox in the left frame "Mobile No"
2. Detail information from the database should be displayed in the right frame where you have "Left, Center, Right".

Thanks
Abd

raf
04-24-2003, 06:16 PM
Abd,

what exactly do you need? Not sure what you ask here.
Do, you have the code to build the listbow and to select and display the info for the form? If so, just post it here and i'll build a frameset. But it's real basic html you'de should master if you want to write some bigger app's.

arnyinc
04-24-2003, 06:29 PM
I think you just need to specify the right frame as the target of the form where you are searching.

<form name="FormName" action="pages.asp" method="post" target="your_right_frame">

This will take the number from the left frame and send the results to the right frame.

Abd
04-24-2003, 06:46 PM
yeah raf, I have the code to build the ComboBoxbox, but I do not have the code to select and display the information at the specified location. Bellow are the codes for, frameset, and building the ComboBox. So I pls need help in the code to select and display the information, you may just use few text fields for the display information.

FRAMESET CODE (frm.asp)
--------------------------------
<html>
<head>
<title>Test</title>
</head>

<FRAMESET ROWS="15%,*">
<FRAME SRC="net.html" NAME=TITLE SCROLLING=NO>

<FRAMESET COLS="10%,*">
<FRAME SRC="side.asp" NAME=SIDEBAR>
<FRAME SRC="center.html" NAME=RECIPES>
</FRAMESET>

<NOFRAMES>
<H1>Data</H1>

<A HREF="recipes.html">no-frames</A> version.
</NOFRAMES>

</FRAMESET>


</html>
--------------------------------------------------------

POPULATING COMBOBOX CODE(side.asp)
-----------------------------------------

<html>
<head>
<title>Test</title>
</head>
<body>

<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "PROVIDER=SQLOLEDB;DATA SOURCE=ABD;UID=sa;PWD=abd;DATABASE=abdul"

Set rs=oConn.execute("Select DISTINCT phonenum from globacom")
FName = RS.Fields("phonenum")


response.write "<font face='arial'><b>Mobile No:</b></font>&nbsp;<select name='txtassignedto'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("phonenum")&""">"&rs("phonenum")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf

rs.close
set rs=nothing
oConn.close
set oConn=nothing

if request.form("action") = "Serrch" then
Response.Redirect"csr1.asp"
end if


%>

<form name="form1" action="csr1.asp" method="post" TARGET="RECIPES">
<center><input type="submit" value="Search" name="action"></center>
</form>



</body>
</html>



I hope I made myself clear now
Thanks raf

raf
04-24-2003, 06:48 PM
Posts crossed.

I'll post some pages later on (must do some other stuff first). Just some stuff i have lying around, but you'll have to customize it with your own data. It basically is just like any ordinary formpage you dynamically build and fill in.

raf
04-24-2003, 08:15 PM
OK. Now the page with the dropdown, you need to place the opening form-tag before the first formelement, so before the dropdown. And the form endtag should be after the submit button. Like



Set rs=oConn.execute("Select DISTINCT phonenum from globacom")
FName = RS.Fields("phonenum")
%>
<form name="form1" action="csr1.asp" method="post" TARGET="RECIPES">
<%
response.write "<font face='arial'><b>Mobile No:</b></font> <select name='txtassignedto'>"&vbcrlf
while not rs.eof
response.write "<option value="""&rs("phonenum")&""">"&rs("phonenum")&"</option>"&vbcrlf
rs.movenext
wend
response.write "</select>"&vbcrlf
rs.close
set rs=nothing
oConn.close
set oConn=nothing

if request.form("action") = "Serrch" then
Response.Redirect"csr1.asp"
end if


%>

<center><input type="submit" value="Search" name="action"></center>

</form>



</body>
</html>

bold = changed. Italic = what does it do? can't it be trown out?

so now you need a page csr1.asp. This page will be loaded in the richt page.
Ther you just make your select. Then have the form. It's always easier if you just create the form (without value, do the layout and stuf, and then you just put in the values. like

D1 : <input type="text" name="xxboordd1" size="4" value="<%=rsrecordsetname.Fields("boordd1")%>">&nbsp;mm<br />
D2 : <input type="text" name="xxboordd2" size="4" value="<%=rsArtikels.Fields("boordd2")%>">&nbsp;mm<br />
L1 : <input type="text" name="xxboordl1" size="4" value="<%=rsArtikels.Fields("boordl1")%>">&nbsp;mm<br />
L2 : <input type="text" name="xxboordl2" size="4" value="<%=rsArtikels.Fields("boordl2")%>">&nbsp;mm<br />

bold = the value from the recordset is set as the value for the textfield. Its just straigth html, with code snippets to paste in the values from the recordset.

Abd
04-25-2003, 11:56 AM
thanks raf,

I have build the file csr1.asp, but when I ran it it give an error message " Object Required" at <b>First Name:</b>
<input name="FirstName" type="text" value="<%=rs.Fields("firstname")%>"><br>

Bellow is the complete code;
<Html>
<head><title>Return Data</title>
</head>
<body>
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "PROVIDER=SQLOLEDB;DATA SOURCE=ABD=sa;PWD=abd;DATABASE=abdul"

Set rs=oConn.execute("Select DISTINCT phonenum from glob ")

rs.close
set rs=nothing
oConn.close
set oConn=nothing

%>

<form name="form1" method="post" action="csr1.asp>
<b>First Name:</b>
&nbsp;<input name="FirstName" type="text" value="<%=rs.Fields("firstname")%>"><br>

<b>Last Name:</b>
&nbsp;<input name="lastname" type="text" value="<%=rs.Fields("lastname")%>" readonly><br>

<b>Middle Name:</b>
&nbsp;<input name="middlename" type="text"value="<%=rs.Fields("middlename")%>" readonly><br>

<b>Home Address:</b>
&nbsp;<input name="homeadd" type="text" size="17" value="<%=rs.Fields("homeadd")%>"><br>

<font color="blue"><b>Phone Number:</b></font>
&nbsp;<input name="phonenum" type="text" size="18" value="<%=rs.Fields("phonenum")%>"><br>

<p align="center"><input type="submit" value="Submit">
</form>
</body>
</html>

-------------------------------------------------------
But with the bellow code replacing the <input type=text;...............................>

<input name="FirstName" type="text" value="<%=Server.HTMLEncode(firstname)%>">

it works but display ONLY one record, if I select another number from the ComboBox it doesn't display, even if I hold down the mouse button. I am thinking may be the problem is moving withing the record set, can you pls help.

Abd

raf
04-25-2003, 01:49 PM
Check the comments below.


<Html>
<head><title>Return Data</title>
</head>
<body>
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open "PROVIDER=SQLOLEDB;DATA SOURCE=ABD=sa;PWD=abd;DATABASE=abdul"

Set rs=oConn.execute("Select DISTINCT phonenum from glob ") see comment 1

rs.close see comment 2
set rs=nothing
oConn.close
set oConn=nothing

%>

<form name="form1" method="post" action="csr1.asp>
<b>First Name:</b>
_<input name="FirstName" type="text" value="<%=rs.Fields("firstname")%>"><br> see comment 3

<b>Last Name:</b>
_<input name="lastname" type="text" value="<%=rs.Fields("lastname")%>" readonly><br>

<b>Middle Name:</b>
_<input name="middlename" type="text"value="<%=rs.Fields("middlename")%>" readonly><br>

<b>Home Address:</b>
_<input name="homeadd" type="text" size="17" value="<%=rs.Fields("homeadd")%>"><br>

<font color="blue"><b>Phone Number:</b></font>
_<input name="phonenum" type="text" size="18" value="<%=rs.Fields("phonenum")%>"><br>

<p align="center"><input type="submit" value="Submit">
</form>
</body>
</html>


comment1 : this query only selects the phonenum from the glob-table. (Each value in that variable will be returned one time.) This means you can only dsplay the phonenum-values !! --> You needed something like
(SELECT firstname, lastname, middelname, homeadd, phonenum FROM glob WHERE phonenum=txtassignedto)
so this will select the values from these variables, from the table glob for the record with the phonenumber that was selected in the dropdown.
I don't know if these variables exist in that table, i just assume this on your code. I also assumed the phonenumber is stored in a numeric variable. If it's stored in a textvariable you need to but 'txtassignedto' in stead of txtassignedto
comment 2 : when you close the recordset, you will nolonger be able to grab values from it. Closing it and setting it to nothing means that all data is completely removed (the nothing clears it from the webservers cache). So you can only close the recordset after you have displayed all the info you needed !!
So they should be placed before the submit button.
like
<%
rs.close
set rs=nothing
oConn.close
set oConn=nothing
%>
comment 3 : you can not display these values cause a) they were never in the recordset since they are not i your selectstatement and b) you have already closed the recordset.
If you fix the other 2 things, this will work
If you display textvalues to the browser, you should best use
server.HTMLEncode(rs.Fields("lastname"))
with numerivc values, the server.HTMLEncode should not be used.
(server.HTMLEncode encodes all html caracters so that they are shown as text in the browser.)

Abd
04-25-2003, 05:24 PM
thanks raf, it work, I only need a script to enable any other number I select from the list to be displayed

Abd

raf
04-25-2003, 06:13 PM
Do ypu mean something like :


("SELECT firstname, lastname, middelname, homeadd, phonenum FROM glob WHERE phonenum=" & request.form("txtassignedto"))


where txtassignedto is the name of the dropdownbox you select the value from. (The dropdownbox must of coarse be in the left framepage, that posts to this page)

Abd
04-25-2003, 07:13 PM
Yeah raf, you are a great GENIUS:thumbsup:
thanks alot, finnaly WOKRS.

Abd



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum