User. xml:
<? XML version = "1.0" encoding = "gb2312" ?>
< User >
< Name > Love flying </ Name >
< Password > 123 </ Name >
< Friendnum > 4 </ Friendnum >
</ User >
Ex35.htm: (main part)
User name: < Input Name = "Username" Type = "Text" ID = "Username" >
< P >
Password: < Input Name = "Password" Type = "Text" ID = "Password" >
</ P >
< P >
< Input Type = "Submit" Name = "Submit" Value = "Submit" Onclick = "Checkuser ()" >
</ P >
< XML ID = "Userxml" SRC = "User. xml" > </ XML >
< Script Language = "JavaScript" >
Function Checkuser ()
{
VaR Usernamenode = Userxml.xmldocument.doc umentelement. selectnodes ( " Name " );
VaR Usernamer = Usernamenode ( 0 ). Firstchild. nodevalue;
VaR Userpasswordnode = Userxml.xmldocument.doc umentelement. selectnodes ( " Password " );
VaR Userpasswordr = Userpasswordnode ( 0 ). Firstchild. nodevalue;
VaR Userfriendnode = Userxml.xmldocument.doc umentelement. selectnodes ( " Friendnum " );
VaR Userfriendn = Userfriendnode ( 0 ). Firstchild. nodevalue;
If (Username. Value = Usernamer && Password. Value = Userpasswordr)
{
Alert ( " Welcome, " + Username. Value + " ! Your address book now has " + Friendnum. Value + " Friend " );
Location. href = " Ex35.xml " ;
}
Else
{
Alert ("Incorrect username and password!");
Clearname ();
Clearpassword ();
}
}
</ Script >
In addition, there is an ex35.xml file used to display the results.
I wrote on the book, but it is always wrong to run ex35.htm, saying "userxml.xmldocument.doc umentelement is empty or not an object".
Please help me!