Build a form - function - combo/select boxes?

G

Guest

Is it possible to extend this function to dynamically create a combo boxes
from the db table....How would do this...I tried passing a 'Select' type to
the function but got a blank entry....Any ideas?

function BuildInput(sType,sName,sValue,iSize,iLength)
select case sType
case "text":
BuildInput = "<INPUT TYPE=""text"" NAME=""" & sName & """ VALUE=""" &
sValue & """ SIZE=""" & iSize & """ MAXLENGTH=""" & iLength & """>"
case "password"
BuildInput = "<INPUT TYPE=""password"" NAME=""" & sName & """ VALUE=""" &
sValue & """ SIZE=""" & iSize & """ MAXLENGTH=""" & iLength & """>"
case "submit"
BuildInput = "<INPUT TYPE=""submit"" NAME=""" & sName & """ VALUE=""" &
sValue & """>"
end select
end function

Response.Write(BuildForm("edituser","post"))

Response.Write(BuildInput("hidden","u_id",Request.QueryString("u_id"),"","")
)
Response.Write("<TABLE>")
Response.Write("<TR><TD>User Name</TD><TD>" & &
BuildInput("text","u_name",escapeString(oRS.fields("u_name")),20,50) &
"</TD></TR>")
Response.Write("<TR><TD>Password</TD><TD>" &
BuildInput("text","u_password",oRS.fields("u_password"),12,12) &
"</TD></TR>")
Response.Write("<TR><TD>First Name</TD><TD>" &
BuildInput("text","u_firstname",escapeString(oRS.fields("u_firstname")),20,5
0) & "</TD></TR>")
Response.Write("<TR><TD>Last Name</TD><TD>" &
BuildInput("text","u_lastname",escapeString(oRS.fields("u_lastname")),20,50)
& "</TD></TR>")
Response.Write("<TR><TD>Email Name</TD><TD>" &
BuildInput("text","u_email",escapeString(oRS.fields("u_email")),20,50) &
"</TD></TR>")
Response.Write("<TR><TD COLSPAN=2>" &
BuildInput("submit","action",ACTIONSAVE,"","") & "</TD></TR>")
Response.Write("</TABLE>"


Many thanks
Jason
 
S

Steven Burn

I'm curious about why you doing this this way?, what exactly is it your
trying to do?

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
C

Chris Hohmann

Is it possible to extend this function to dynamically create a combo boxes
from the db table....How would do this...I tried passing a 'Select' type to
the function but got a blank entry....Any ideas?

No, but here are two (2) functions I use. DBCFS is for single-select mode
select controls, DBLSS is for multi-select mode select controls.

<%
Function DBCFS(strConn,strSQL,varSelectedKey)
'I/O:
'--> strConn : Connection String
'--> strSQL : SQL Statement OR "Table" Name
'--> varSelectedKey : Variant that identifies which option should be
selected
'Notes:
'The function expects strSQL to return at least two(2) columns.
'Column 1 will be used to populate the value attribute of the option tag
'Column 2 will be used to populate the content of the option tag, ie. what
gets displayed

'Determine command type
Dim re, lngOptions
Set re = New RegExp
re.Pattern = "^\s*(SELECT|EXEC)"
re.IgnoreCase = True
If re.Test(strSQL) Then
lngOptions = &H1 'Command Text
Else
lngOptions = &H2 'Table
End If

'Get the data
Dim conn, rs, arr
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn
Set rs = conn.Execute(strSQL,,lngOptions)
If Not rs.EOF Then arr = rs.GetRows()
rs.Close : Set rs = Nothing
conn.Close : Set conn = Nothing

'Build the option tags
Dim j,o
o=""
If IsArray(arr) Then
For j = 0 to UBound(arr,2)
o=o & "<option value=""" & Server.HTMLEncode(arr(0,j)) & """"
If arr(0,j) = varSelectedKey Then
o=o & " selected"
End If
o=o & ">" & Server.HTMLEncode(arr(1,j)) & "</option>" & vbCRLF
Next
Else
o=o & "<option>[No Option Data]</option>"
End If
DBCFS = o
End Function

Function DBLSS(strConn,strSQL)
'I/O:
'--> strConn : Connection String
'--> strSQL : SQL Statement OR "Table" Name
'Notes:
'The function expects strSQL to return at least three(3) columns.
'Column 1 will be used to populate the value attribute of the option tag
'Column 2 will be used to populate the content of the option tag, ie. what
gets displayed
'Column 3 determines if the select attribute should be set for the option
tag

'Determine command type
Dim re, lngOptions
Set re = New RegExp
re.Pattern = "^\s*(SELECT|EXEC)"
re.IgnoreCase = True
If re.Test(strSQL) Then
lngOptions = &H1 'Command Text
Else
lngOptions = &H2 'Table
End If

'Get data
Dim conn, rs, arr
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn
Set rs = conn.Execute(strSQL,,lngOptions)
If Not rs.EOF Then arr = rs.GetRows()
rs.Close : Set rs = Nothing
conn.Close : Set conn = Nothing

'Build option tags
Dim j,o
o=""
If IsArray(arr) Then
For j = 0 to UBound(arr,2)
o=o & "<option value=""" & Server.HTMLEncode(arr(0,j)) & """"
If arr(2,j) Then
o=o & " selected"
End If
o=o & ">" & Server.HTMLEncode(arr(1,j)) & "</option>"
Next
Else
o=o & "<option>" & strSQL & "</option>"
End If
DBLSS = o
End Function
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top