XMLHttpRequest创建智能表单
码形式)。本例中的PHP代码是用PHP 4编写的,但在PHP 5中这些代码也能照常运行。
打开文本编辑器并输入下列代码: <html> <head> <title>Form Field Validation</title> <style type="text/css"> .fieldname { text-align: right; } .submit { text-align: right; } </style> <script type="text/javascript" src="HttpRequest.js"></script> <script type="text/javascript"> function checkUsername() { var userValue = document.getElementById("username").value; if (userValue == "") { alert("Please enter a user name to check!"); return; } var url = "formvalidator.php?username=" + userValue; var request = new HttpRequest(url, checkUsername_callBack); request.send(); } function checkUsername_callBack(sResponseText) { var userValue = document.getElementById("username").value; if (sResponseText == "available") { alert("The username " + userValue + " is available!"); } else { alert("We’re sorry, but " + userValue + " is not available."); } } function checkEmail() { var emailValue = document.getElementById("email").value; if (emailValue == "") { alert("Please enter an email address to check!"); return; } var url = "formvalidator.php?email=" + emailValue; var request = new HttpRequest(url, checkEmail_callBack); request.send(); } function checkEmail_callBack(sResponseText) { var emailValue = document.getElementById("email").value; if (sResponseText == "available") { alert("The email " + emailValue + " is currently not in use!"); } else { alert("I’m sorry, but " + emailValue + " is in use by another user."); } } </script> </head> <body> <form> <table> <tr> <td class="fieldname"> Username: </td> <td> <input type="text" id=&q |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |