Two examples _php skills of ajax+php while learning and practicing

Source: Internet
Author: User
Tags visibility
Effect 1. When the mouse is placed on a day, if there is a memo on the day, it will be displayed, the following figure:

Copy Code code as follows:

function Checkfortasks (Thedate, E) {
Find Taskbox <div> set to visible in page
Theobject = document.getElementById ("Taskbox");
theObject.style.visibility = "visible";
Initialize Taskbox position
var posx = 0;
var posy = 0;
Locate Taskbox position as mouse position
POSX = E.clientx + document.body.scrollLeft;
Posy = E.clienty + document.body.scrollTop;
TheObject.style.left = posx + "px";
TheObject.style.top = posy + "px";
Set up the PHP request page
Serverpage = "taskchecker.php?thedate=" + thedate;
Set PHP return Data replacement location
ObjID = "Taskbox";
var obj = document.getElementById (ObjID);
Send request and load return data
Xmlhttp.open ("Get", serverpage);
Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate = = 4 && xmlhttp.status = 200) {
obj.innerhtml = Xmlhttp.responsetext;
}
}
Xmlhttp.send (NULL);
}

Effect 2. When the mouse clicks on a day to enter the name, the system will automatically retrieve the existence of the name, and can be filled in the Name box, as shown:

Copy Code code as follows:

Function AutoComplete (Thevalue, E) {
Locate the <div> position of the Autocompletediv in the page (showing the label that retrieves the name)
Theobject = document.getElementById ("Autocompletediv");
Set to visible
theObject.style.visibility = "visible";
TheObject.style.width = "152px";
Set Retrieve label location
var posx = 0;
var posy = 0;

Posx = (Findposx (document.getElementById ("yourname")) + 1);
Posy = (Findposy (document.getElementById ("yourname")) + 23);

TheObject.style.left = posx + "px";
TheObject.style.top = posy + "px";
Setting Events for keyboard entry
var Theextrachar = E.which;

if (Theextrachar = = undefined) {
Theextrachar = E.keycode;
}
Set Load Search list location
var ObjID = "Autocompletediv";

Set the PHP request page and pass the user's name to the past (taking into account the backspace effect)
if (Theextrachar = = 8) {
if (thevalue.length = = 1) {
var serverpage = "autocomp.php";
}
else{
var serverpage = "autocomp.php" + "sstring=" + thevalue.substr (0, (thevalue.length-1));
}
}
else{
var serverpage = "autocomp.php" + "? sstring=" + Thevalue + string.fromcharcode (Theextrachar);
}
Send request and load return data
var obj = document.getElementById (ObjID);
Xmlhttp.open ("Get", serverpage);
Xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate = = 4 && xmlhttp.status = 200) {
obj.innerhtml = Xmlhttp.responsetext;
}
}
Xmlhttp.send (NULL);
}

File package Download

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.