验证表单元素

/*  
 *  awx<a href="[email protected]">An Weixiao</a>
 *
 * 
 *
/*--------------------------------------------------------------------------*/ 
    /**
     *how to define obj
     *obj = {name:"the param's name, id as default",
     *       value:"the param's value,",
     *       feedback:"the data area id to show the check result"
     *      }
     *
     *how to use it
     *    checkMethod('url',obj)
     *
     *    for this ,we can use it in jsp/html.. like this:
     *    checkMethod("/check.do",{name:'id',value:'id_value',feedback:'feedback'});
     */
    
 function checkMethod(url,obj/*The request parameter object has name and value fields*/){
   obj = checkPairObject(obj);
   if(obj.value !=""){
      document.getElementById(obj.feedback).innerHTML = "wait for ....";
      send_request(url,obj);
   } else {
      alert("error input!");
   }
 }
 
 function checkPairObject(obj){
   if(obj==null)obj = {};
   var name = obj.name;
   var value = obj.value;
   var feedback = obj.feedback;
      if(obj.name == null){
     obj.name = "id";
   }
   if(obj.value== null){
     obj.value="";
   }
   if(obj.feedback==null){
     obj.feedback="feedback";
   }
   return obj;
 }
 
 var http_request = false;
 function createPostParam(obj/*object to generate name and value and returned text area id */){
      obj = checkPairObject(obj);
   var pair_param = obj.name+"="+obj.value;
   return pair_param;
 }
 
 function send_request(url,obj) {
  var queryString = createPostParam(obj);
  http_request = false;
  if(window.XMLHttpRequest) { //Mozilla
   http_request = new XMLHttpRequest();
   if (http_request.overrideMimeType) {//MiME
    http_request.overrideMimeType('text/xml');
   }
  }
  else if (window.ActiveXObject) { // IE
   try {
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
   }
  }
  if (!http_request) { //
   return false;
  }
  http_request.open("POST", url, true);
  http_request.onreadystatechange = function(){processRequest(obj.feedback);}
  http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");   
        http_request.send(queryString);
 }
 
    function processRequest(show_return_area_id) {
  var f = document.form1;
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
    var returnStr = http_request.responseText;
    if(returnStr.indexOf("Error")==-1) {
     //document.getElementById(show_return_area_id).innerHTML =returnStr;
     alert(returnStr);
    }
    else {
     //document.getElementById(show_return_area_id).innerHTML =returnStr;
     alert(returnStr);
    }
            } else {
                   // document.getElementById(show_return_area_id).innerHTML = "Error";
                   alert("error!");
            }
        }
    }

你可能感兴趣的:(xml,jsp,IE,Microsoft,F#)