|
This is a level-2 Association menu implemented using Ajax technology and is associated with databases. Code As follows:
1. Post Article JSP
<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" Import = "Java. SQL. *, xztj. bean. *, xztj. form. * "errorpage =" "%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> post </title>
<Script language = "JavaScript" src = "/xztj/JS/showsubject. js"> </SCRIPT>
<Script language = "JavaScript">
_ Editor_url = "/JS /";
VaR win_ie_ver = parsefloat (navigator. appversion. Split ("MSIE") [1]);
If (navigator. useragent. indexof ('mac')> = 0) {win_ie_ver = 0 ;}
If (navigator. useragent. indexof ('windows ce ')> = 0) {win_ie_ver = 0 ;}
If (navigator. useragent. indexof ('Opera ')> = 0) {win_ie_ver = 0 ;}
If (win_ie_ver> = 5.5 ){
Document. Write ('<SCR' + 'ipsrc = "'+ _ editor_url + 'editor. js "');
Document. Write ('language = "javascript1.2"> </scr '+ 'ipt ');
} Else {document. Write ('<SCR' + 'ipt'> function editor_generate () {return false ;}</scr '+ 'ipt'> ');}
Function check (){
VaR copyfrom = Document. getelementbyid ("articlesource ");
If (document. form1.self [0]. Checked ){;
Copyfrom. style. Display = "NONE ";
} Else
If (document. form1.self [1]. Checked ){;
Copyfrom. style. Display = "";
}
}
</SCRIPT>
<Style type = "text/CSS">
<! --
. Style1 {font-size: 18px}
. Style4 {font-size: 14px}
-->
</Style>
</Head>
<Body>
<Form name = "form1" method = "Post" Action = "">
<Div align = "center" class = "style1">
<P> post an article
</P>
<Table width = "636" Height = "418" border = "1" bordercolor = "#66cc99">
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> topic: </span> </div> </TD>
& Lt; TD width = "475" & gt; <Div align = "Left" & gt;
<Select id = "specialclassid" onchange = "refreshlist ()">
<Option value = ""> select a topic </option>
<%
Java. util. Vector vector = articleclassbean. getinstance (). articleclassshow ();
Articleclassform AF;
For (INT I = 0; I <vector. Size (); I ++ ){
AF = (articleclassform) vector. Get (I );
Int classid = AF. getclassid ();
String classname = AF. getclassname ();
%>
<Option value = "<% = classid %>"> <% = classname %> </option>
<% }%>
</SELECT>
</Div> </TD>
</Tr>
<Tr class = "tdbg">
<TD> <Div align = "Left"> <SPAN class = "style4"> topic: </span> </div> </TD>
<TD> <Div align = "Left">
<Select id = "specialid">
<Option value = ""> select a topic </option>
</SELECT>
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> Article Title: </span> </div> </TD>
<TD> <Div align = "Left">
<Input type = "text" name = "title">
</Div> </TD>
</Tr>
<Tr>
<TD> <p align = "Left" class = "style4"> author: </P> </TD>
<TD> <Div align = "Left">
<Input type = "text" name = "author">
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> Email: </span> </div> </TD>
<TD> <Div align = "Left">
<Input type = "text" name = "email">
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> Article attributes: </span> </div> </TD>
<TD> <Div align = "Left">
<Input type = "radio" name = "self" value = "1" onclick = "check ()">
<SPAN class = "style4"> original </span>
<Input type = "radio" name = "self" value = "2" onclick = "check ()">
<SPAN class = "style4"> reprint </span> </div> </TD>
</Tr>
<Tr class = "tdbg" id = "articlesource" style = "display: none">
<TD> <Div align = "Left"> <SPAN class = "style4"> conversion from: </span> </div> </TD>
<TD> <Div align = "Left">
<Input name = "copyfrom" type = "text" id = "copyfrom" value = "" size = "50" maxlength = "255">
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> keywords: </span> </div> </TD>
<TD> <Div align = "Left">
<Input type = "text" name = "keyword">
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> Article content: </span> </div> </TD>
<TD> <Div align = "Left">
<Textarea name = "content" Cols = "25" rows = "10"> </textarea>
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> Article type: </span> </div> </TD>
<TD> <Div align = "Left">
<Label>
<Input type = "checkbox" name = "ontop" value = "checkbox">
<SPAN class = "style4"> Solid top </span> </label>
<SPAN class = "style4">
<Label> </label>
</Span>
<Label>
<Input type = "checkbox" name = "Elite" value = "checkbox">
<SPAN class = "style4"> excellent articles </span> </label>
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> image: </span> </div> </TD>
<TD> <Div align = "Left">
<Input type = "radio" name = "ispic" value = "1">
<SPAN class = "style4"> Yes </span>
<Input type = "radio" name = "ispic" value = "2">
<SPAN class = "style4"> NO </span> </div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> Entry Clerk: </span> </div> </TD>
<TD> <Div align = "Left">
<Input type = "text" name = "inputer">
</Div> </TD>
</Tr>
<Tr>
<TD> <Div align = "Left"> <SPAN class = "style4"> whether to go through review </SPAN >:</div> </TD>
<TD> <Div align = "Left">
<Input name = "passed" type = "checkbox" value = "checkbox" Checked>
</Div> </TD>
</Tr>
<Tr>
<TD> </TD>
<TD> <Div align = "Left">
<Input type = "Submit" name = "Submit" value = "Publish now">
<Input type = "reset" name = "Submit" value = "reset">
</Div> </TD>
</Tr>
</Table>
<P> </P>
</Div>
</Form>
</Body>
</Html>
2. js files
// JavaScript document
VaR xmlhttpreq;
Function createxmlhttprequest (){
If (window. XMLHttpRequest ){
Xmlhttpreq = new XMLHttpRequest ();
}
Else if (window. activexobject ){
Try {
Xmlhttpreq = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Xmlhttpreq = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
}
Function sendrequest (URL ){
Createxmlhttprequest ();
Xmlhttpreq. Open ("Post", URL, true );
Xmlhttpreq. onreadystatechange = processresponse;
Xmlhttpreq. Send (null );
}
Function processresponse (){
If (xmlhttpreq. readystate = 4 ){
If (xmlhttpreq. Status = 200 ){
Updatelist ();
} Else {
Window. Alert ('error ');
}
}
}
//
Function refreshlist (){
VaR section = Document. getelementbyid ("specialclassid"). value;
If (Section = ""){
Clearlist ();
Return;
}
VaR url = "/xztj/special. do? Method = showspecialbyid & id = "+ section;
Sendrequest (URL)
}
function updatelist () {
clearlist ();
var Product = document. getelementbyid ("specialid");
var Results = xmlhttpreq. responsexml. getelementsbytagname ("specialname");
var option = NULL;
for (VAR I = 0; I option = document. createelement ("option");
option. appendchild (document. createtextnode (results . firstchild. nodevalue);
product. appendchild (option);
}< BR >}
function clearlist () {
var Product = document. getelementbyid ("specialid");
while (product. childnodes. length> 0) {
product. removechild (product. childnodes [0]);
}< BR >}< br> I would like to share with you.
|