Tutorials to .com

Tutorials to .com » Asp » Xml » Html how to add dynamic Form of documents

Html how to add dynamic Form of documents

Print View , by: iSee ,Total views: 21 ,Word Count: 3548 ,Date: Wed, 22 Apr 2009 Time: 10:48 AM

Hello everyone, today and talk to you about how to use asp to dynamically add Html document Form of the question. If you are more familiar with Html know for sure if there is a <form> </ form> tag in HTML. In <form> and </ form> type, such as between the (type) to Text, Password, Button, Submit, Reset, etc. tag (element). We are talking about here to add the dynamic of Form refers to the addition of dynamic <Form> </ Form> element of the Text. How to dynamically add the Form of it?

Analysis of the first analysis, we add a form of dynamic ideas.

If this is so that your own or use such as FrontPage, DreamWeaver static Html document to increase the preparation of one type of text, then elements of the form. You must be finished the first type of form element for the text, and then will join the second type of form for the text element has been added so far to meet the number of conditions. In Canada we let us not refer to a new type of element for the text should be there already exists and the contents of text types as well as the other form elements are displayed. Mentioned above through the static Html document prepared for the text to increase the type of form element methods, in fact, the procedure is that we document in ASP to add the type of dynamic text elements in the form of basic ideas. How to get that already exist and there is the content of text types as well as other elements of the contents of this form? In the ASP program through request.form ( "TextFieldName") can be. Which "TextFieldName" refers to <form> </ form> in the name for the "TextFieldName" items. Means <form> <input type = text name =
"TextFieldName"> </ form> in the "TextFieldName".

Now we know how to get the contents of the form, then we will be able to get through this approach and have the content already exists, the type of form element for the text of the value. Then show that the text has been of value, we will be able to get the value assigned to the corresponding item. Next, we will want to know how to have a total number of content types for the form of this text? We can to get this way. That is, through the request.form ( "TextFieldName") to get the Count property. This is because the form has been a number of types of the same name as the Text and form elements, we can get is a set of values, it is said that their value is placed on a collection of TextFieldName. While the count attribute is the collection of statistics on the number of similar elements, so that we can know the total number of such type is the text of the form elements, and loop can be removed with the count attribute of the value of their collections. You may ask: how can we get this set for each type of TextFieldName a text element in the form of the value of it? Prior to this, we first define a variable I, it is the initial value of 1, in fact, the variable I is what we are doing at the time of the cycle variables. Then we can through the request.form ( "TextFieldName") (I) of the method to obtain a TextFieldName each type of form element for the text of the value. Another point to note is that we have in the value of text types as well as the form element's value is assigned to retrieve and display the corresponding item, we should also add a new type of form of text. Why? This is to allow and then we can continue to add new value. Otherwise, the value has been taken out of all the type of form element text, you do not continue to add new value of the place, and that it could not add Html Dynamic Form of the document. So, you must not forget this very important point. Now we know how to meet the conditions of these text types of the form for the number of elements, and also know how to obtain respectively the value of their respective. How do I control will only have value only, the type of form for the text elements of it? And our realization of exactly how to do everything mentioned above? Well, next I will give its source code, and will add some comments or explanation given.
'/ * DynamicAddForm.asp document the source code starting point * /
<% @ Language = VBScript%>
<%
'----------------------------------------------
'Author: WaiWai (YY)
'Created Date: 2000-2-20
'File Name: DynamicAddForm.ASP
'Description: Dynamic Add Form's Text Fields.
'All Rights Reserved. Title to the City Club.
'----------------------------------------------
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title> Dynamic Add Form Text Elements. </ title>
<style type="text/css">
<! --
td (font-size: 9pt)
body (font-size: 9pt)
select (font-size: 9pt)
A (text-decoration: none; color: # 003366; font-size: 9pt)
A: hover (text-decoration: underline; color: # FF0000; font-size: 9pt)
->
</ style>
</ HEAD>
<BODY>
<table border="1" cellspacing="0" height=400 width=98% bordercolorlight="#5E5E00" bordercolordark="#FFFFEC" bgcolor=LightGrey align=center valign=top>

<%
if trim (Request.Form ( "List")) = "show that there are items of" then
'/ * Of the trim () function is removed from Request.Form ( "List") on both sides of the space * /

'/ * When you click on the "show has been of" button, we will see the value of all types have the form for text items * /
Response.Write "<td> <form> <center> elements have been kept is:" & "</ td> <tr>"
for I = 1 to Request.Form ( "items"). Count '/ * already exists the number of types of Text * /
Response.Write "<td align=center>" & Request.Form ( "items") (I) & "</ td> <tr>"
next
if trim (Request.Form ( "newItem "))<>"" then
Response.Write "<td align=center>" & trim (Request.Form ( "newItem")) Response.write "<input type = button name = 'Back' value = 'Back' Response.write" style = 'font -size: 12pt 'onClick =' window.history.back () '>
'/ * Click the button <Back> will return to the previous page, or add text type for the Form of the pages where * /
Response.write "</ form> </ td> <tr>"
end if
else '/ * at this time indicates that the user is clicking on the "Add" button to add the operation * /
Response.Write "<td align=center> <form action=DynamicAddForm.asp method=post> </ td>"
for I = 1 to Request.Form ( "items"). Count
'/ * At this time is the cycle of operation shows that already exists and the type of production value for the text of the form element * /
'/ * Request.Form ( "items"). Count already exists for the number of types of Text * /
'/ * Here we can add content to include the conditions of the judge. Add content as judged by the length of less than 3, such as whether or not .* /
Response.Write "<td align=center> <input type = text name = items value = '"
Response.write Request.Form ( "items") (I) & "'></ td> <tr> "
'/ * This step is to get the type of a value for the text of the form element's value is displayed * /
next
if trim (Request.Form ( "newItem")) <> "" then
'/ * The purpose of this step is to check whether the user to add a new type of form element for the text there does not add a new value, * /
'/ * There is this value assigned to name = items of the type of form element for the text and displayed. * /
Response.Write "<td align=center> <input type = text name = items value = '"
Response.Write trim (Request.Form ( "newItem")) & " '"
Response.Write "> <br> </ td> <tr>"
Response.Write "<td align=center> <input type=text name=newItem" Response.write "value=''> </ td> <tr>"
'/ * Here is to add a newItem type of form element for the text so that users can add operation to continue. * /
else
'/ * At this time indicates that the user to add a new type of form element for the text which do not add a new value, it can only list * /
'/ * NewItem type a text of the form elements, so that users can add operation to continue. * /
Response.Write "<td align=center> <input type=text name=newItem value=''> </ td>"
end if
%>
<tr> <td align=center> <br>
<input type=submit name="List" value="" style="font-size:12pt">
<input type=submit name="Add" value="" style="font-size:12pt">
</ form>
</ td>
<%
end if
%>
</ table>
</ BODY>
</ HTML>
'/ * DynamicAddForm.asp document the end of the source code point * /

You read the source code of these, you may notice there are two types of form for the text elements: a name for the items, a name for newItem. Why? This is because what we have to distinguish between users by clicking the <Add> "button, and enter a new value received, which is that we have to allow users to enter a new value can be the type of form for the text elements. So that we will be able to clearly set out in the cycle when the user has only to add, and the type of the value of the text elements of the form. This is why we named them as the names of different reasons, is not it wonderful? :-) Ha ha. In fact, the key to this approach is to use the request.form ( "TextFieldName") and the Count property request.form ( "TextFieldName") (I) of the method, it allows us to more easily access the type known as TextFieldName the text the number of elements of form and obtain their values, respectively. The usefulness of these two methods a lot, you can greatly simplify our code to be prepared. We must remember that the two Usage. Here I would like to give a usage of these two did not use the ASP source code, we compare the comparison, you understand better why the code above.

'/ * DynamicAddForm2.asp document the source code starting point * /
<% @ Language = VBScript%>
<%
'------------------------------------------------- ---
'Author: WaiWai (YY)
'Created Date: 2000/1/13
'File Name: DynamicAddForm.ASP
'Description: Dynamic Add Form's Text Fields.
'All Rights Reserved. Title to the City Club
'------------------------------------------------- ---
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</ HEAD>
<style type="text/css">
<! --
td (font-size: 9pt)
body (font-size: 9pt)
select (font-size: 9pt)
A (text-decoration: none; color: # 003366; font-size: 9pt)
A: hover (text-decoration: underline; color: # FF0000; font-size: 9pt)
->
</ style>
<title> Add new mail server site. All Rights Reserved. </ title>
<script language=javascript>
function mycheck (tt) (
alert ( "afd")
return false
)
</ script>
<BODY Topmargin=12>
<form name=form1 method=post>
<table border="1" cellspacing="0" height=400 width=98% bordercolorlight="#5E5E00" bordercolordark="#FFFFEC" bgcolor=LightGrey align=center valign=top>
<td align=center colspan=5 valign=top height=30>
<h4> additional information on the new mail server </ h4>
</ td> <tr>
<td align=center valign=top height=10> <font style="font-size:11pt"> Number </ font> </ td>
<td align=center valign=top height=10 width=43%> <font style="font-size:11pt"> mail server URL </ font> </ td>
<td align=center valign=top height=20 width=17%> <font style="font-size:11pt"> username variable parameters </ font> </ td>
<td align=center valign=top height=20 width=17%> <font style="font-size:11pt"> password variable parameters </ font> </ td>
<td align=center valign=top height=20 width=17%> <font style="font-size:11pt"> Site Name </ font> </ td>
<tr>
<td colspan=5 valign=top height=30>
<font color=blue> [* * * Example: * * *] <br>
0. 990.net/prog/login?

user


pass 990.net
</ font>
</ td>
<tr>
<%
if trim (Request.form ( "num "))="" then
'/ * At this time that the first user to open the ASP page, so from the num is empty, and shows the corresponding input interface for the user to enter information
'Which is the num value to record the type of form to text the number of elements, with the first code in the document' request.form ( "items"). Count the same effect .* /
'/ * First time open this page .* /
Response.Write "<td align=center valign=top> 1. </ Td>"
Response.Write "<input type=hidden name=num value=1>"
Response.Write "<td align=center valign=top>"
Response.Write "<input type=text size=40 name=url1> </ td>"
Response.Write "<td align=center valign=top> <input type=text size=12 id=text1 name=user_var1> </ td>" & vbcrlf
Response.Write "<td align=center valign=top> <input type=text size=12 id=text2 name=pw_var1> </ td>"
Response.Write "<td align=center valign=top> <input type=text size=12 id=text2 name=sitename1> </ td> <tr>"
else
'/ * Add new * /
'Response.Write "<td align=center valign=top>" & trim (Request.Form ( "num")) & ". </ Td>"
'/ * Loop Start * /
Response.Write "<td colspan=5 valign=top>"
for I = 1 to cint (trim (Request.Form ( "num ")))+ 1
%>
<% = I%>.
<% If I <10 then
'/ * The purpose here is to ensure that elements of the first 10 months after the 89 elements with the same width indent * /%>

<% Elseif I <100 and I> 9 then%>

<% End if%>
<% If I <> cint (trim (Request.Form ( "num ")))+ 1 then
url = "url" & I '/ * generated as url1, url2 ...... string * /
user_var = "user_var" & I
pw_var = "pw_var" & I
sitename = "sitename" & I
if trim (request.form (url ))<>"" and trim (Request.Form (user_var ))<>"" and_ trim (Request.Form (pw_var ))<>"" and trim (Request.Form (sitename ))<>"" then%>
<input type = text size = 40 name = <% = url%> value = <% = trim (request.form (url ))%>>
<input type = text size = 12 id = text1 name = <% = user_var%> value = <% = trim (Request.Form (user_var ))%>>
<input type = text size = 12 id = text2 name = <% = pw_var%> value = <% = trim (Request.Form (pw_var ))%>>
<input type = text size = 12 id = text2 name = <% = sitename%> value = <% = trim (Request.Form (sitename ))%>>
<br>
<% Else
%>
<script>
alert ( "mail server URL, user name variable parameters, the password parameter variables, the value of the site name in time!")
window.history.back ()
</ script>
<% Exit for
end if
else%>
<input type = text size = 40 name = url <% = I%>>

<input type = text size = 12 id = text1 name = user_var <% = I%>>

<input type = text size = 12 id = text2 name = pw_var <% = I%>>
<input type = text size = 12 id = text2 name = sitename <% = I%>>
<br>
<% End if
next
'/ * Loop End * /
end if
%>
</ td>
<tr>
<td colspan=5 align=center height=20>
<input type = button value = "additional" style = "font-size: 11pt"
onclick = "(document [ 'form1']. action = 'DynamicAddForm.ASP';
document.form1.submit ();}">
<input type = Button value = "preserve" style = "font-size: 11pt"
onclick = "document [ 'form1']. action = 'SaveNew.asp';
document.form1.submit ();">

<input type = button value = "back to the console" style = "font-size: 11pt"
onClick = "window.location = 'PostOfficeConsole.asp'">
</ td>
</ table>
<% If trim (Request.Form ( "num "))<>"" then
'/ * When the beginning of the first type to the text added to the form element when the value of the type of element records the number of text * /%>
<input type = hidden name = num value = <% = cint (trim (Request.Form ( "num ")))+ 1%>>
<% End if%>
</ form>
</ BODY>
</ HTML>
'/ * DynamicAddForm2.asp document the end of the source code point * /

Now we all have seen this in two ways to achieve their respective program source code. Do you have any ideas? Oh, is not that the first than the second code simple code for this. We are in the first program code is to be of the same name in the text of the form type of the value of elements used in the request.form ( "TextFieldName") of the Count property to statistics so far a total number of elements of such a form. While in the second program code, we are through <form> </ form> in the type of hidden elements to store and get this number. Another point worth repeating again and that is to make these types of form elements for the text name of the same name as the name. This can be avoided in the second program code such as "url =" url "& I" part of the. Of course, this approach is to know in request.form ( "TextFieldName") have the Count property, under the premise that only the mind. So the first advantage of code is that it makes full use of the same name in obtaining the same type of form element attribute value and the value of the Count of. Oh, good problem-solving method is based on ideas and tools on a full understanding of the basis. . All of these, the key is we have to do constant, so that we can better comprehend and understand, learning to have better ways even more interesting.


Asp and XML related Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.