My ajax message board has a good source program and js application.

Source: Internet
Author: User
Tags setf

Copy codeThe Code is as follows: // JavaScript Document
Function $ (id)
{
Return document. getElementById (id );
}
Function echo (obj, html)
{
$ (Obj). innerHTML = html;
}
Function fopen (obj)
{
$ (Obj). style. display = "";
}
Function fclose (obj)
{
$ (Obj). style. display = "none ";
}
Function lTrim (str)
{
If (str. charAt (0) = "")
{
// If the first character on the left of the string is a space
Str = str. slice (1); // remove spaces from the string
// This sentence can also be changed to str = str. substring (1, str. length );
Str = lTrim (str); // recursive call
}
Return str;
}

// Remove the spaces on the right of the string
Function rTrim (str)
{
Var iLength;

ILength = str. length;
If (str. charAt (iLength-1) = "")
{
// If the first character on the right of the string is a space
Str = str. slice (0, iLength-1); // remove spaces from the string
// This sentence can also be changed to str = str. substring (0, iLength-1 );
Str = rTrim (str); // recursive call
}
Return str;
}

// Remove the spaces on both sides of the string
Function trim (str)
{
Return lTrim (rTrim (str ));
}
Function sck (s)
{
Return s. replace (/\ n/g, "[br]");
// S = s. replace (chr (13) & chr (23), "<br/> ");
// Return s;
}
Function f (obj)
{
Return trim (eval ("document. forms [0]." + obj + ". value "));
// Return trim ($ (obj). value );
}
Function setf (obj)
{
Return eval ("document. forms [0]." + obj + ". focus ();");
}
Function show (obj)
{
Var s = $ (obj). style;
S. display = s. display = "none "? "": "None ";
}
Function echo (obj, html)
{
$ (Obj). innerHTML = html;
}
Function createxmlhttp ()
{
Var xmlhttp = false;
Try {
Xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e ){
Try {
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e ){
Xmlhttp = false;
}
}
If (! Xmlhttp & typeof XMLHttpRequest! = 'Undefined '){
Xmlhttp = new XMLHttpRequest ();
If (xmlhttp. overrideMimeType) {// sets the MiME category
Xmlhttp. overrideMimeType ('text/xml ');
}
}

Return xmlhttp;
}
Function getnum (url, obj)
{
// Var B = "";
Var xmlhttp = createxmlhttp ();
If (! Xmlhttp)
{
Alert ("your browser does not support XMLHTTP !! ");
Return;
}
Xmlhttp. onreadystatechange = requestdata;
Xmlhttp. open ("GET", url, true );
Xmlhttp. send (null );
Function requestdata (){
If (xmlhttp. readyState = 4)
{
If (xmlhttp. status = 200)
{
$ (Obj). value = xmlhttp. responseText;
}
}
}
}
Function getdata (url, obj1, obj2)
{

Var xmlhttp = createxmlhttp ();
If (! Xmlhttp)
{
Alert ("your browser does not support XMLHTTP !! ");
Return;
}
Xmlhttp. onreadystatechange = requestdata;
Xmlhttp. open ("GET", url, true );
Xmlhttp. send (null );
Function requestdata ()
{

Fopen (obj1 );
Echo (obj1, "loading data. Please wait ......");
If (xmlhttp. readyState = 4)
{
If (xmlhttp. status = 200)
{
If (obj1! = Obj2) {fclose (obj1 );};
Echo (obj2, xmlhttp. responseText );

}
}

}
}
Function postdata (url, obj, data)
{
Var xmlhttp = createxmlhttp ();
If (! Xmlhttp)
{
Alert ("your browser does not support XMLHTTP !! ");
Return;
}
Xmlhttp. open ("POST", url, true );
Xmlhttp. onreadystatechange = requestdata;
Xmlhttp. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded ");
Xmlhttp. send (data );
Function requestdata ()
{
Fopen (obj );
Echo (obj, "submitting data. Please wait ......");
// Alert (xmlhttp. readyState );
If (xmlhttp. readyState = 4)
{
// Alert (xmlhttp. status );
If (xmlhttp. status = 200)
{
Echo (obj, xmlhttp. responseText );
}
}
}
}
Function checkform (obj, id)
{
If (f ("user") = "")
{
Alert ("please give me your name !! ");
Setf ("user ");
Return false;
}
If (f ("user"). length> 10 & f ("user") <2)
{
Alert ("the name can only be 2-10 characters long !! ");
}
If (f ("title") = "")
{
Alert ("Enter the message title !! ");
Setf ("title ");
Return false;
}
If (f ("title"). length> 50)
{
Alert ("sorry, the title is too long !! ");
Setf ("title ");
Return false;
}
If (f ("content") = "")
{
Alert ("The message content cannot be blank !! ");
Setf ("content ");
Return false;
}
Data = "user =" + escape (f ("user") + "& title =" + escape (f ("title ")) + "& content =" + escape (document. forms [0]. content. value) + "& reply =" + escape (f ("reply "));
// Alert (data );
// Data = "content =" + escape (sck (f ("content ")));
If (obj = "add ")
{
// Alert (obj );
Postdata ("file. asp? Action = addsave "," contentdata ", data );
} Else if (obj = "reply ")
{
Postdata ("file. asp? Action = replysave "," contentadmin "+ id, data );
}
Return true;
}
Function adminlogin ()
{
If ($ ("adminuser"). value = "")
{
Alert ("the management account cannot be blank! ");
$ ("Adminuser"). focus ();
Return false;
}
If ($ ("adminpwd"). value = "")
{
Alert ("the management password cannot be blank! ");
$ ("Adminpwd"). focus ();
Return false;
}
Data = "adminuser =" + escape ($ ("adminuser"). value) + "& adminpwd =" + escape ($ ("adminpwd"). value );
Postdata ("file. asp? Action = checkadmin "," loginlist ", data );
Return true;
}
Function adreset ()
{
$ ("Adminuser"). value = "";
$ ("Adminpwd"). value = "";
}
Function linktool ()
{
If ($ ("linktool"). innerHTML = "self-help link ")
{
$ ("Linktool"). innerHTML = "Link ";
Getdata ("list. asp? Action = addlink "," linklist "," linklist ");

} Else
{

$ ("Linktool"). innerHTML = "self-help link ";
Getdata ("list. asp? Action = linklist "," linklist "," linklist ");
}
}
Function addlink ()
{
If ($ ("home"). value = "")
{
Alert ("the website name cannot be blank ");
$ ("Home"). focus ();
Return false;
}
If ($ ("url"). value = "")
{
Alert ("the website address cannot be blank! ");
$ ("Url"). focus ();
Return false;
}
Data = "home =" + escape ($ ("home"). value) + "& url =" + escape ($ ("url"). value );
Postdata ("list. asp? Action = linksave "," linklist ", data );
Return true;
}
Function linkreset ()
{
$ ("Home"). value = "";
$ ("Url"). value = "";
}
Function updatepwd ()
{
If (f ("user") = "")
{
Alert ("Enter the management account! ");
Setf ("user ");
Return false;
}
If (f ("npwd") = "")
{
Alert ("Enter the management password! ");
Setf ("npwd ");
Return false;
}
If (f ("npwd ")! = F ("npwd1 "))
{
Alert ("the new password is different from the Confirm Password !! ");
Setf ("npwd ");
Return false;
}
Data = "user =" + escape (f ("user") + "& pwd =" + escape (f ("npwd "));
Postdata ("list. asp? Action = savepwd "," contentdata ", data );
Return true;
}
Function updateinfo ()
{
If (f ("gonggao") = "")
{
Alert ("announcement content cannot be blank! ");
Setf ("gonggao ");
Return false;
}
If (f ("foot") = "")
{
Alert ("the copyright information cannot be blank! ");
Setf ("foot ");
Return false;
}
Data = "news =" + escape (document. forms [0]. gonggao. value) + "& foot =" + escape (document. forms [0]. foot. value );
Postdata ("list. asp? Action = infosave "," contentdata ", data );
Return true;
}

Package File Download

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.