ASP retrieves data from dynamic forms and writes it to an XML file. It is displayed in XSL.

Source: Internet
Author: User
Tags id3 xsl

<HTML>
<Head>
<Title> untitled document </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Script language = "JavaScript">
VaR currow = NULL;
Var y = 1;

Function selectrow (){
VaR E = Window. event;
VaR tr1 = E. srcelement;
If (currow)
Currow. bgcolor = "# ffffff ";
Tr1.bgcolor = "e7e7e7 ";
Currow = tr1;
}
Function addrow (SRC ){
// Alert (SRC );
VaR newrow = SRC. insertrow (SRC. Rows. Length-1 );
Newrow. attachevent ("onclick", selectrow );
Newrow. Height = 20;
VaR I = 4;

While (I --){
VaR Newcell = newrow. insertcell ();

Switch (I ){
Case 0: Newcell. innerhtml = '<input type = "button" onclick = "javascript: delrow (this. parentelement. parentelement) "value =" delete this row "> '+ (Y ++ );
Document. All. Count. value = Y-1;
Break;
Case 1: Newcell. innerhtml = div2.innerhtml; break;
Case 2: Newcell. innerhtml = div3.innerhtml; break;
Case 3: Newcell. innerhtml = div4.innerhtml; break;
Default: Newcell. innerhtml = div1.innerhtml; break;

}
}
// Alert (newrow. outerhtml );
}

Function delrow (SRC ){

VaR tab = SRC. parentelement;
VaR I = tab. Rows. length;
VaR J = tab. Rows. length;
While (I --){
If (src = tab. Rows [I]) {
// Alert ("this is the line ----" + I );
Document. All. Count. value = J-3;
Tab. deleterow (I );

}

}
}
</SCRIPT>
</Head>

<Body>
<Form name = "form1" Action = "2.asp" method =" Post "onsubmit = return (checkv ()>
<H3> enter the dealer's communication information: Last name: <input type = "text" name = "jxname"> <br>
Address: <input type = "text" name = "jxadd"> <br>
Tel: <input type = "text" name = "jxtel"> <br>
Enter inventory information <br>
<Table id = "TB" width = "100%" border = "1" align = "center" cellpadding = "1" cellspacing = "1" style = "border-collapse: collapse "bordercolor =" #111111 ">
<Tr>
<TH scope = "col" width = "25%"> product name </Th>
<TH scope = "col" width = "25%"> specification </Th>
<TH scope = "col" width = "25%"> Inventory </Th>
<TH scope = "col" width = "25%"> operation </Th>
</Tr>
<Tr id = "blankrow" onclick = "addrow (this. parentelement)">
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</Tr>
</Table>
<Input type = "hidden" name = "count" value = "count">
<Input type = "Submit" id = "btnsub" name = "btnsub" value = "Submit"> <br>
</Form>
<Div id = "div1" style = "display: none"> <input id = "TXT" type = "text" name = "ID" style = "width: 97%; background-color: # ffffef "> </div>

<Div id = "div2" style = "display: none"> <input id = "TXT" type = "text" name = "id1" style = "width: 97%; background-color: # ffffef "value =" 11 "> </div>
</Body>
<Div id = "div3" style = "display: none"> <select name = "ID2" style = "width: 97%; Background-color: # ffffef">
<Option value = "box"> box </option>
<Option value = "item"> item </option>

</SELECT> </div>
<Div id = "div4" style = "display: none"> <input id = "TXT" type = "text" name = "ID3" style = "width: 97%; background-color: # ffffef "value =" 33 "> </div>
<Script language = "JavaScript">
Function checkv ()
{

If (form1.jxname. value. Length = 0)
{
Alert ("enter your name and address! ");
Form1.jxname. Focus ();
Return false;
}

Else if (! (Check_number (form1.id1. Value )))
{
Alert ("the number can only be a number ")
Form1.id1. Focus ();
Return false;
}
Else
Return (true );
}
Function check_number (Myint)
{

VaR checkok = "0123456789 ";
VaR checkstr = Myint;
VaR allvalid = true;
VaR decpoints = 0;
VaR allnum = "";
For (I = 0; I <checkstr. length; I ++)
{
Ch = checkstr. charat (I );
For (j = 0; j <checkok. length; j ++)
If (CH = checkok. charat (j ))
Break;
If (j = checkok. length)
{
Allvalid = false;
Break;
}
Allnum + = CH;
}
If (! Allvalid)
{
Return (false );
}
Return (true );
}

</SCRIPT>
</Html>

2. asp file

<%
'// obtain the form data
response. write ("Total" + request. form ("count") + "record")
I = request. form ("count")
jxname = request. form ("jxname")
jxadd = request. form ("jxadd")
jxtel = request. form ("jxtel")
response. write (request. form ("jxname")
response. write ("
")
response. write (request. form ("jxadd")
response. write ("
")
response. write (request. form ("jxtel")
response. write ("
")
str1 = trim (request. form ("id1")
str2 = trim (request. form ("ID2")
str3 = trim (request. form ("ID3")
arraya = Split (str1, ",")
arrayb = Split (str2 ,",")
arrayc = Split (str3, ",")

For I = 0 to ubound (arraya)
Response. Write "<li>" & arrayc (I) & "--" & arrayb (I) & "--" & arraya (I)
Next
'// Write the XML file
Dim objdom
Dim objroot
Dim objchild1
Dim objchild2
Dim objchild3
Dim objchild4
Dim objpi
Dim pinode
Set objdom = server. Createobject ("Microsoft. xmldom ")
'// Write Style
Set pinode = objdom. createprocessinginstruction ("XML-stylesheet", "Type = 'text/XSL'

Href = 'list. XSL '")
Objdom. appendchild pinode
'// Create a root contact
Set objroot = objdom. createelement ("kucunbiao ")

Objdom. appendchild objroot
Set objchild1 = objdom. createelement ("jxname ")
Objchild1.text = jxname

Objroot. appendchild objchild1

Set objchild2 = objdom. createelement ("jxadd ")
Objchild2.text = jxadd

Objroot. appendchild objchild2
Set objchild3 = objdom. createelement ("jxtel ")
Objchild3.text = jxtel
Objroot. appendchild objchild3
Set objchild4 = objdom. createelement ("kucun ")
Objroot. appendchild objchild4
For I = 0 to ubound (arraya)
Set objfield = objdom. createelement ("field ")

'Create the attribute taborder.
Set objatttaborder = objdom. createattribute ("taborder ")

'Set the attribute value of taborder
Objatttaborder. Text = I

'Append the attribute value of taborder to the field element.
Objfield. setattributenode objatttaborder

'Create a new element field_value.
Set objfieldvalue2 = objdom. createelement ("name ")
Objfieldvalue2.text = arrayc (I)
Set objfieldvalue = objdom. createelement ("guige ")

Objfieldvalue. Text = arrayb (I)
Set objfieldvalue1 = objdom. createelement ("shuliang ")
Objfieldvalue1.text = arraya (I)
'Append the field element as the child element of the root element.
Objchild4.appendchild objfield

'Append field_value as the sub-element content
Objfield. appendchild objfieldvalue
Objfield. appendchild objfieldvalue1
Objfield. appendchild objfieldvalue2
Next
Set objpi = objdom. createprocessinginstruction ("XML", "version = '1. 0 '")

Objdom. insertbefore objpi, objdom. childnodes (0)

Objdom. Save "F: \ XML \" & jxname & ". xml"
'// Release the resource
Set objdom = nothing
Set objroot = nothing
Set objfield = nothing
Set objfieldvalue = nothing
Set objattid = nothing
Set objatttaborder = nothing
Set objpi = nothing
Set pinode = nothing
%>
3. Use XSL to display submitted XML, list. XSL

<? XML version = "1.0" encoding = "gb2312"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

<XSL: template match = "/">
<HTML>
<Body style = "Background: # dfeebb"> <left>
<H3> name: <XSL: value-of select = "kucunbiao/jxname"/> <H3> address: <XSL: value-of select = "kucunbiao/jxadd"/>

<H3> Tel: <XSL: value-of select = "kucunbiao/jxtel"/> <Table border = "1" width = "600">

<XSL: Apply-templates select = "kucunbiao/kucun">

</XSL: Apply-templates>

</Table> </left>
</Body>
</Html>
</XSL: Template>
<XSL: template match = "kucun">

<Tr>
<TD width = "60%"> <Div align = "center"> name </div> </TD>
<TD width = "20%"> <Div align = "center"> type </div> </TD>
<TD width = "20%"> <Div align = "center"> quantity </div> </TD>
</Tr>
<XSL: For-each select = "field">
<Tr>
<TD> <XSL: value-of select = "name"/> </TD>
<TD> <XSL: value-of select = "guige"/> </TD>
<TD> <XSL: value-of select = "shuliang"/> </TD>
</Tr>
</XSL: For-each>

</XSL: Template>

</XSL: stylesheet>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.