Build a form - function - combo/select boxes?

Discussion in 'ASP General' started by Guest, Aug 9, 2004.

  1. Guest

    Guest 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
     
    Guest, Aug 9, 2004
    #1
    1. Advertising

  2. Guest

    Jeff Cochran Guest

    Is this what you're trying to do?

    http://www.devasp.com/samples/populatedropdown.asp

    Jeff

    On Mon, 9 Aug 2004 13:10:24 -0400, <> wrote:

    >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
    >
     
    Jeff Cochran, Aug 9, 2004
    #2
    1. Advertising

  3. Guest

    Steven Burn Guest

    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!


    <> wrote in message
    news:#...
    > 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
    >
    >
     
    Steven Burn, Aug 9, 2004
    #3
  4. <> wrote in message
    news:%...
    > 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
    %>
     
    Chris Hohmann, Aug 10, 2004
    #4
  5. Guest

    Bullschmidt Guest

    Bullschmidt, Aug 10, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles B. Summers
    Replies:
    6
    Views:
    748
    kayodeok
    Jun 28, 2004
  2. Dan Watson

    Select combo boxes

    Dan Watson, Aug 25, 2004, in forum: HTML
    Replies:
    2
    Views:
    418
    David Dorward
    Aug 25, 2004
  3. Bodidily

    Re: Select combo boxes

    Bodidily, Aug 25, 2004, in forum: HTML
    Replies:
    0
    Views:
    386
    Bodidily
    Aug 25, 2004
  4. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    599
    Bob Barrows [MVP]
    Nov 16, 2005
  5. ddog

    Form validation and combo boxes

    ddog, Nov 22, 2006, in forum: Javascript
    Replies:
    2
    Views:
    162
Loading...

Share This Page