Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    many text box need to loop into database using ASP.

    dear,

    i have more than 20 textboxes to allow user key in and save into database(SQL SERVER) but the number of textboxes is not hard-coded. Example now there are 10 textboxes, user can fill in different text boxes n may be it may be blank too.
    example:

    name1 : text box 1
    email1 : textbox 2

    name2 : text box 3
    email1 : text box 4
    email2 : text box 5

    name3 : text box 6
    email1 : text box 7
    email2 : text box 8

    name4 : text box 9
    email1 : text box 10


    SO, u can c there are 10 textboxes. after user enter data, at the next page, i want to show ONLY what user entered, if user just enter name1 & name3, then i will show the name only,.... that's mean i dun want show all the record that blank fill in, i just want to show ONLY that user enrtered.

    how ?

    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's one way to do it:

    Code:
    <% @Language="VBScript" %>
    <% Option Explicit %>
    <%
    
    'Dim the variables you're going to use to ensure they are global
    Dim name1, email1, EmailGood, pass, objRegExp, IsValid
    
    '******************************** Validate Email
    Function ValidEmail(x)
         Set objRegExp = New RegExp
         objRegExp.Pattern = "^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}$"
         objRegExp.IgnoreCase = True
         IsValid = objRegExp.Test(x)
              If IsValid Then
                   ValidEmail = TRUE
              Else
                   ValidEmail = FALSE
              End If
    End Function
    '******************************** Validate Email
    
    
    'Pass is a variable I'm going to use to see if the form has already been filled out
    pass = Request.Form("pass")
    pass = pass + 1
    
    
    'Get the variables from the previous form (which is on this page!)
    name1 = Request.Form("name1")
    email1 = Request.Form("email1")
    
    
    'Check for a valid email entry
    EmailGood = ValidEmail(email1)
    
    'This decides what to display
    
    If pass = 1 Then
         DisplayForm()
    Else
         DisplayEntries()
    End If
    %>
    
    
    <% Sub DisplayForm() %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    <title>Example Form</title>
    </head>
    <body>
    Please fill out the form below:<br />
         <form name="myform" method="post" action="exampleform.asp">
              <input type="text" name="name1" value="<% = name1 %>" /><br />
              <input type="text" name="email1" value="<% = email1 %>" /><br />
              <input type="hidden" name="pass" value="<% = pass %>" />
              <input type="submit" value="submit" />
         </form>
    </body>
    </html>
    <% End Sub %>
    
    
    <% Sub DisplayEntries() %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    <title>Example Form</title>
    </head>
    <body>
    You entered:<br />
         <form name="myform" method="post" action="exampleform.asp">
    <% If name1 <> "" Then Response.Write("          <input type=""text"" name=""name1"" value=""" & name1 & """ /><br />") %>
    <% If email1 <> "" AND EmailGood = True Then Response.Write("          <input type=""text"" name=""email1"" value=""" & email1 & """ /><br />") %>
    Was the email good?: <% = EmailGood %>
         </form>
    </body>
    </html>
    <% End Sub %>
    Last edited by whammy; 08-24-2002 at 01:07 PM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    i think you've already asked this similar question before. anyway, here's another solution:


    name your fields with so that you can identify the textboxes with hidden fields, buttons, etc.

    <input type="text" name="txt_name1"><br>
    <input type="text" name="txt_email1"><br>
    <input type="text" name="hid_email1"><br>
    <input type="submit" name="btn_submit" value="submit" />

    then in the next page:

    ...
    <form>
    <%
    response.write "These are what you entered:<br>"
    for each item in request.form
    if instr(1,item,"txt_")=1 and request.form(item)<>"" then
    response.write "<input name='" & item & "' value='" & request.form(item) & "'><br>"
    end if
    next
    %>
    </form>
    ...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •