...

View Full Version : many text box need to loop into database using ASP.



NinjaTurtle
08-23-2002, 05:41 AM
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 ?

:thumbsup:

whammy
08-24-2002, 01:56 PM
Here's one way to do it:



<% @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 %>

glenngv
08-26-2002, 11:07 AM
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>
...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum