มีโค้ดสองส่วนเวลาทำงานรวมกันแล้วerrorแต่ถ้าแยกกันไม่errorต้องทำ


    <script language="javascript">



    var p="";

    var t="";

    var a="";

    var total;



    function setP(pid){

     p = pid;

    }

    function setT(tid){

     t = tid;

     //alert(t);

    }

    function setA(aid){

     a = aid;

    }

    var HttPRequest = false;

    function doCallAjax(Mode) {

      

         if (window.XMLHttpRequest) { // Mozilla, Safari,...

         HttPRequest = new XMLHttpRequest();

         if (HttPRequest.overrideMimeType) {

         HttPRequest.overrideMimeType('text/html');

         }

         } else if (window.ActiveXObject) { // IE

         try {

         HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");

         } catch (e) {

         try {

            HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");

         } catch (e) {}

         }

         }

        

         if (!HttPRequest) {

         alert('Cannot create XMLHTTP instance');

         return false;

         }

         var url = 'tran_add.php';

         var pmeters = "promis_num=" + encodeURI( document.getElementById("txtpromis_num").value) +

           "&bDate=" + encodeURI( document.getElementById("txtdate").value ) +

           "&date_promis=" + encodeURI( document.getElementById("txtdate_promis").value ) +

           "&member_id=" + encodeURI( document.getElementById("txtmember_id").value ) +

           "&or_name_str=" + encodeURI( document.getElementById("txtname_str").value ) +

           "&or_sur_str=" + encodeURI( document.getElementById("txtor_sur_str").value ) +

           "&address=" + encodeURI( document.getElementById("txtaddress_str").value ) +

           "&number=" + encodeURI( document.getElementById("txtnumber").value ) +

           "&moo=" + encodeURI( document.getElementById("txtmoo").value ) +

           "&tanon=" + encodeURI( document.getElementById("txttanon").value ) +

           "&tumbon1=" + encodeURI( document.getElementById("txttumbon_1").value ) +

           "&amphur1=" + encodeURI( document.getElementById("txtamphur_1").value ) +

           "&province1=" + encodeURI( document.getElementById("txtprovince_1").value ) +

           "&Time=" + encodeURI( document.getElementById("txttimee").value ) +

           "&or_name_end=" + encodeURI( document.getElementById("txtor_name_end").value ) +

           "&or_cargo=" + encodeURI( document.getElementById("txtor_cargo").value ) +

           "&or_name_cargo=" + encodeURI( document.getElementById("txtor_name_cargo").value ) +

           "&or_weight_cargo=" + encodeURI( document.getElementById("txtWeight").value ) +

           "&or_company_end=" + encodeURI( document.getElementById("txtor_company_end").value ) +

           "&or_addres_end=" + encodeURI( document.getElementById("txtor_addres_end").value ) +

           "&moo_end=" + encodeURI( document.getElementById("txtmoo_end").value ) +

           "&tanon_end=" + encodeURI( document.getElementById("txttanon_end").value ) +

           "&or_provincee=" + encodeURI( p) +//document.getElementById("province").value

           "&or_amphur=" + encodeURI(a) +//document.getElementById("amphur").value

           "&or_tumbon=" + encodeURI(t) + //document.getElementById("tumbon").value

           "&or_select_car=" + encodeURI( document.getElementById("txtor_car").value ) +

           "&date_due=" + encodeURI( document.getElementById("txtdate_due").value ) +

           "&or_payprogram=" + encodeURI( total ) +

          // "&tor_status=" + encodeURI( document.getElementById("txtor_status").value ) +

           "&tMode=" + Mode;

        //alert(pmeters);

        HttPRequest.open('POST',url,true);

     

        HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        HttPRequest.setRequestHeader("Content-length", pmeters.length);

        HttPRequest.setRequestHeader("Connection", "close");

        HttPRequest.send(pmeters);

        

        

        HttPRequest.onreadystatechange = function()

        {

     

          if(HttPRequest.readyState == 3)  // Loading Request

           {

            document.getElementById("mySpan").innerHTML ="<image src='pictu/indicator_flower.gif'>";

           }

     

          if(HttPRequest.readyState == 4) // Return Request

           {

            window.location = 'AjaxPHPRegister3.php';

         }

         else

         {

          document.getElementById("mySpan").innerHTML = HttPRequest.responseText;

         }

         {

          // alert(HttPRequest.responseText);

        //    document.getElementById("mySpan").innerHTML = HttPRequest.responseText;

           /* document.getElementById("txtpromis_num").value = '';

            document.getElementById("txtmember_id").value = '';

            document.getElementById("txtdate").value = '';

            document.getElementById("txtdate_promis").value = '';

            document.getElementById("txttimee").value = '';

            document.getElementById("txtname_str").value = '';

            document.getElementById("txtor_sur_str").value = '';

            document.getElementById("txtaddress_str").value = '';

            document.getElementById("txtnumber").value = '';

            document.getElementById("txtmoo").value = '';

            document.getElementById("txttanon").value = '';

            document.getElementById("txttumbon_1").value = '';

            document.getElementById("txtamphur_1").value = '';

            document.getElementById("txtprovince_1").value = '';

            document.getElementById("txttimee").value = '';

            document.getElementById("txtor_name_end").value = '';

            document.getElementById("txtcargo").value = '';

            document.getElementById("txtor_name_cargo").value = '';

            document.getElementById("txtWeigth").value = '';

            document.getElementById("txtor_company_end").value = '';

            document.getElementById("txtor_address_end").value = '';

            document.getElementById("txtmoo_end").value = '';

            document.getElementById("txttanon_end").value = '';

            document.getElementById("txtor_province").value = '';

            document.getElementById("txtor_select_car").value = '';

            document.getElementById("txtdate_due").value = '';

            document.getElementById("txtr_payprogram").value = '';

            document.getElementById("txtor_status").value = '';*/


           }

         

        }

       

        }

    // Start XmlHttp Object



    function chkFrm(){

     

      var txtaddress_str = document.getElementById("txtaddress_str").value;

      var txttumbon_1 = document.getElementById("txttumbon_1").value;

      var txtamphur_1 = document.getElementById("txtamphur_1").value;

      var txtor_name_end = document.getElementById("txtor_name_end").value;

      var txtor_name_cargo = document.getElementById("txtor_name_cargo").value;

      var txtor_cargo = document.getElementById("txtor_cargo").selectedIndex; 

      var txtor_name_cargo = document.getElementById("txtor_name_cargo").value;

      var txtWeight = document.getElementById("txtWeight").value;

      var txtor_company_end = document.getElementById("txtor_company_end").value;

      

      

      

      if(txtaddress_str==""){

         alert("กรุณากรอกสถานที่สินค้าขึ้น");

         return;

      }

      else if(txttumbon_1==0){

         alert("กรุณาระบุตำบล");

         return;

      }

      else if(txtamphur_1==0){

         alert("กรุณาระบุอำเภอ");

         return;

      }

      else if(txtor_name_end==""){

         alert("กรุณากรอกชื่อผูู้รับ");

         return;

      }

      else if(txtor_cargo==0){

         alert("กรุณาระบุประเภทสินค้า");

         return;

      }

      else if(txtor_name_cargo==""){

         alert("กรุณากรอกระบุชื่อสินค้า");

         return;

      }

      else if(txtWeight==""){

         alert("กรุณากรอกน้ำหนัก");

         return;

      }  

      else if(txtor_company_end==""){

         alert("กรุณากรอกชื่อลงสินค้า");

         return;

      }  

      else  

       doCallAjax();



    }

    function uzXmlHttp(){

        var xmlhttp = false;

        try{

            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

        }catch(e){

            try{

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            }catch(e){

                xmlhttp = false;

            }

        }

     

        if(!xmlhttp && document.createElement){

            xmlhttp = new XMLHttpRequest();

        }

        return xmlhttp;

    }

    // End XmlHttp Object

    function select_data(id,value1){

        var result;

        var url = 'amphur.php?id=' + id + '&value1='+value1 ;   

     //alert(url);

        xmlhttp = uzXmlHttp();

        xmlhttp.open("GET", url, false);

        xmlhttp.send(null);

     document.getElementById(id).innerHTML =  xmlhttp.responseText;

     

     //document.all.tumbon.style.display='none';



       if(id=='amphur'){

         var url = 'amphur.php?id=tumbon&value1=' ;   

       //alert(url);

       xmlhttp = uzXmlHttp();

       xmlhttp.open("GET", url, false);

       xmlhttp.send(null);

       //alert(xmlhttp.responseText);

         document.getElementById('tumbon').innerHTML =  xmlhttp.responseText;

       }

    }

    function strOK(num){

        // ??? form ? num1,num2

      /*  var province = document.form2.txtprovince_1.value;

       var amphur = document.form2.txtamphur_1.value;

       var tumbon = document.form2.txttumbon_1.value;*/


        var province = p;

        var amphur = a;

        var tumbon = t;

      

        var txtWeight = document.form2("txtWeight").value;

        var result;

     var url = 'ok.php?province=' + province + '&amphur='+ amphur + '&tumbon=' +tumbon + '&txtWeight=' + txtWeight;   

     //alert(url);

        xmlhttp = uzXmlHttp();

        xmlhttp.open("GET", url, false);

        xmlhttp.send(null);

        result = xmlhttp.responseText;

     //alert(result);

     var stemp = xmlhttp.responseText;

     var temp = stemp.split("//\\");

     total=temp[1];

     //alert(total);

        document.getElementById('result2').innerHTML =  temp[0];

    }

    window.onLoad=select_data("province",'');

    window.onLoad=select_data("amphur", '');

    window.onLoad=select_data("tumbon", '');

    function Inint_AJAX() {

       try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE

       try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE

       try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript

       alert("XMLHttpRequest not supported");

       return null;

    };

    //dochange จะถูกเรียกเมื่อมีการเลือก รายการ Combobox ซึ่งจะทำให้ไปเรียก AJAX เพื่อร้องขอข้อมูลถัดไปจาก Server

    function dochange(src, val) {

      alert(req); // debug

      req.onreadystatechange = function () {

        if (req.readyState==4) {

          if (req.status==200) {

            document.getElementById(src).innerHTML=req.responseText; //รับค่ากลับมา

          }

        }

      };

      req.open("GET", "province.php?data="+src+"&val="+val); //สร้าง connection

      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // set Header

      req.send(null); //ส่งค่า

    }

    //เรียกครั้งแรกไปทำการโหลด อำเภอ มาแสดง

    window.onLoad=dochange('txtamphur_1', -1);

    </script>

    สีแดงส่วนแรก สีเหลืองส่วนที่สองถ้าจะรวมกันต้องทำไง เวลารวมกันแล้วมัoฟ้องบรรทัด var txtWeight = document.form2("txtWeight").value;  ฟ้องobject require


02 ธ.ค. 2553 เวลา 20:12 น. 1 1,168
^