SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    'undefined' is null or not an object

    Hi,

    Good day!

    I encountered error : 'undefined' is null or not an object when i type on my two textboxes :

    Code:
    echo "<label class='LLabel'> Material Barcode: </label>";
        echo "<input type='password' name='barcode' id='barcode' value='' onkeypress='get_data();' size='40' class='LField'>";
        echo "<br/><br/>";
        echo "<label class='LLabel'> Warehouse Barcode: </label>";
        echo "<input type='password' name='barcode_wh' id='barcode_wh' value='' onkeypress='get_wh()' size='40' class='LField'>";
    here is my index.php
    PHP Code:
    <?php
        date_default_timezone_set
    ('Asia/Manila'); //set the time zone
        
    include('includes/connection.php');
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="javascript/wms.js"> </script>
    <script type="text/javascript" src="javascript/prompt.js"> </script>
    <script type="text/javascript" src="javascript/notification.js"> </script>

    <link rel="stylesheet" type="text/css"  href="css/prompt.css">
    <link rel="stylesheet" type="text/css"  href="css/notify.css">
    <link rel="stylesheet" type="text/css"  href="css/wms.css">
    <title>Warehouse Barcoding</title>
    </head>
    <body onLoad="document.getElementById('barcode').focus();">
    <form name="wms" action="" method="post">
    <?php
    $dateEntry 
    date("Y-m-d h:i:s");
        echo 
    "<div>";
        echo 
    "<label class='LLabel'>DateTime: </label>";
        echo 
    "<input type='text' name='date_entry' id='date_entry' value='$dateEntry' onkeypress='get_data();' size='40' class='LField' style='border:none;'>";
        echo 
    "<br/><br/>";
        echo 
    "<label class='LLabel'> Material Barcode: </label>";
        echo 
    "<input type='password' name='barcode' id='barcode' value='' onkeypress='get_data();' size='40' class='LField'>";
        echo 
    "<br/><br/>";
        echo 
    "<label class='LLabel'> Warehouse Barcode: </label>";
        echo 
    "<input type='password' name='barcode_wh' id='barcode_wh' value='' onkeypress='get_wh()' size='40' class='LField'>";

        echo 
    "</div>";
    //$barcode = '10001CHE00102401100200250000.50';
        
    echo "<div id='display_data'>";
        echo 
    "<table>";
        echo 
    "<tr>";
        echo 
    "<th>PO Number</th>";
        echo 
    "<th>Unique ID</th>";
        echo 
    "<th>Kind</th>";
        echo 
    "<th>Item Code</th>";
        echo 
    "<th>Description</th>";
        echo 
    "<th>UoM</th>";
        echo 
    "<th>Supplier</th>";
        echo 
    "<th>Quantity</th>";
        echo 
    "</tr>";
        
        echo 
    "<tr>";
        echo 
    "<td><input type='text' name='po_number' id='po_number' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "<td><input type='text' name='unique_id' id='unique_id' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "<td><input type='text' name='kind' id='kind' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "<td><input type='text' name='material_code' id='material_code' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "<td><input type='text' name='description' id='description' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "<td><input type='text' name='uom' id='uom' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "<td><input type='text' name='supplier' id='supplier' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";    
        echo 
    "<td><input type='text' name='qty' id='qty' value='' readonly='readonly' disabled='disabled' class='text_field'></td>";
        echo 
    "</tr>";
        echo 
    "</table>";    
        echo 
    "</div>";    
        
        echo 
    "<div id='display_wh'>";
        echo 
    "<table>";
        echo 
    "<tr>";
        echo 
    "<th>Warehouse #</th>";
        echo 
    "<th>Row #</th>";
        echo 
    "<th>Rack #</th>";
        echo 
    "<th>Level</th>";
        echo 
    "</tr>";
        
        echo 
    "<tr>";
        echo 
    "<td><input type='text' name='whse' id='whse' value='' readonly='readonly' disabled='disabled' class='text_field_wh'></td>";
        echo 
    "<td><input type='text' name='row' id='row' value='' readonly='readonly' disabled='disabled' class='text_field_wh'></td>";
        echo 
    "<td><input type='text' name='rack' id='rack' value='' readonly='readonly' disabled='disabled' class='text_field_wh'></td>";
        echo 
    "<td><input type='text' name='level' id='level' value='' readonly='readonly' disabled='disabled' class='text_field_wh'></td>";
        echo 
    "</tr>";
        echo 
    "</table>";    
        echo 
    "</div>"
        
        echo 
    "<input type='hidden' name='barcode_mat_data' id='barcode_mat_data' value=''>";
        echo 
    "<input type='hidden' name='barcode_wh_data' id='barcode_wh_data' value=''>";
    ?>
    </form>
    </body>
    </html>
    and my wms.js
    Code:
    var loadingmessage = '<center>Getting material info ... <img src="images/loading.gif" /></center>';
    function AJAX(){
        var xmlHttp;
        try{
            xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
            return xmlHttp;
            }
        catch (e){
            try{
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
                return xmlHttp;
                }
            catch (e){
                try{
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    return xmlHttp;
                    }
                catch (e){
                    alert("Your browser does not support AJAX!");
                    return false;
                    }
                }
            }
        }
        
    function notify(message) {
        if (document.getElementById('notice') !== null) {
            document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box
        }
        alerter('images/dunlop1.jpg','Warehouse Barcoding System',message);
    }
    
    function refresh(time){
     setTimeout("location.reload(true);",time);
     
    }
    
    //----barcode mat---//
    function get_data(){
        if (window.event.keyCode==13 || window.event.keyCode==10) {
        var barcode_wms = document.getElementById("barcode").value;
        var divid = "display_data";
        var url = "getbarcode_data.php";
        var str = "mc=" + barcode_wms;
        var xmlHttp = AJAX();
    
       //alert(xmlHttp);
        xmlHttp.onreadystatechange=function(){
        //alert("test");
       /*
        if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){
          //  document.getElementById(divid).innerHTML=loadingmessage;
            }
        */    
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
         //   alert('test');
                var jsonart = xmlHttp.responseText;
                //jsonart = jsonart.replace(/^\s+|\s+$/g, "");
           //     alert(jsonart);
                if (jsonart.replace(/\s+/g, '') == "Invalid") {
                // alert("Invalid Barcode");
                 
                   notify("Invalid Material Barcode");
                 //document.getElementById('barcode').value = '';
                 //document.getElementById('barcode').focus();
                 refresh(1500);
                }
                else
                {
                  //  alert("Correct Barcode");
                  
                var strsplit = jsonart.split("^");
                document.getElementById("po_number").value = strsplit[0];
                document.getElementById("unique_id").value = strsplit[1];
                document.getElementById("kind").value = strsplit[2];
                document.getElementById("material_code").value = strsplit[3];
                document.getElementById("description").value = strsplit[4] ;
                document.getElementById("uom").value = strsplit[5] ;
                document.getElementById("supplier").value = strsplit[6] ;           
                document.getElementById("qty").value = strsplit[7] ;
                document.getElementById("barcode_mat_data").value = strsplit[8] ;
                
                
                document.getElementById('barcode').disabled = true;
    
                 document.getElementById('barcode_wh').value = '';
                 document.getElementById('barcode_wh').focus();
                
                
                }
                }
            //}
        }
        }
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", str.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(str);
       // }
    }
    //}
    
    
    //----barcode warehouse---//
    //var myVar;
    function get_wh(){
        if (window.event.keyCode==13 || window.event.keyCode==10) {
        var barcode_wh = document.getElementById("barcode_wh").value;
        var divid = "display_wh";
        var url = "getbarcode_wms.php";
        var str = "wh=" + barcode_wh;
        //alert(str);
        var xmlHttp = AJAX();
    
       //alert(xmlHttp);
        xmlHttp.onreadystatechange=function(){
       // alert("test");
       /*
        if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){
          //  document.getElementById(divid).innerHTML=loadingmessage;
            }
        */    
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
         // alert('tes');
                var jsonart = xmlHttp.responseText;
                //jsonart = jsonart.replace(/^\s+|\s+$/g, "");
                //alert(jsonart);
                if (jsonart.replace(/\s+/g, '') == "Invalid") {
                 //alert("Invalid Barcode");
                 
                // document.getElementById('barcode_wh').value = '';
                // document.getElementById('barcode_wh').focus();
                   notify("Invalid Warehouse Barcode");
                  // myVar=setInterval(function(){clearinterval()},1500)
                 
                 //refresh(1500);
                 
                    document.getElementById('barcode_wh').value = '';
                    document.getElementById('barcode_wh').focus();
    
                    return false;  
                }
                else
                {
                  //  alert("Correct Barcode");
                  var strsplit = jsonart.split("^");
                 document.getElementById("whse").value = strsplit[0];
                document.getElementById("row").value = strsplit[1];
                document.getElementById("rack").value = strsplit[2];
                document.getElementById("level").value = strsplit[3];
                document.getElementById("barcode_wh_data").value = strsplit[4] ;
                
                document.getElementById('barcode_wh').disabled = true;
                
                save();
                
                
                }
                }
            //}
        }
        }
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", str.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(str);
       // }
    }
    //}
    
    //----save---//
     function save() {
     var myVar;    
      ajaxRequest = AJAX();
        ajaxRequest.onreadystatechange=function() {
    
        if (ajaxRequest.readyState==4 && ajaxRequest.status==200)
        {
                //alert('test');
           var result = ajaxRequest.responseText;
             //alert();
            //  alert (result);
    
               if (result == "failed")
               {
                document.getElementById('barcode_wh').disabled = false;
                document.getElementById('barcode_wh').value = "";
                document.getElementById('barcode_wh').focus();
                notify("Please scan again.");
               }
    
               else (result == "saved|saved" || result == "saved|saved|saved" || result == "saved|saved|saved|saved" ||result == "saved|saved|saved|saved|saved" || result == "saved|saved|saved|saved|saved|saved" || result == "saved|saved|saved|saved|saved|saved|saved")
               {
                  notify("Transaction has been saved");
                  //window.setTimeout("clearinterval();",2000);
                 // myVar=setInterval(function(){clearinterval()},2000)
                 refresh(1500);
    
               }
    
           }
        }
        
                 var unique_id = document.getElementById('unique_id').value;   
                 var date_entry = document.getElementById('date_entry').value;
                 var po_number = document.getElementById('po_number').value;    
                 var kind = document.getElementById('kind').value;
                 var barcode_mat_data = document.getElementById('barcode_mat_data').value;     
                 var barcode_wh_data = document.getElementById('barcode_wh_data').value;
                 var qty = document.getElementById('qty').value;
                       
                 var parameters = "&unique_id="+unique_id+"&date_entry="+date_entry+"&po_number="+po_number+"&kind="+kind+"&barcode_mat_data="+barcode_mat_data+"&barcode_wh_data="+barcode_wh_data+"&qty="+qty;
                 
                 alert(parameters);
    
    var url = "centralPost_barcode_wms.php";
    ajaxRequest.open("POST", url, true);
    //ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
    ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxRequest.setRequestHeader("Content-length", parameters.length);
    ajaxRequest.setRequestHeader("Connection", "close");
    ajaxRequest.send(parameters);
    }
    and my getbarcode_data.php
    PHP Code:
    <?php
    include("includes/connection.php");
    if(
    $_POST["mc"])
     {
        
    $barcode $_POST['mc'];
        
    $po_number substr($barcode05);  
        
    $item_code substr($barcode56);  
        
    $supplier substr($barcode113);  
        
    $uom substr($barcode142); 
        
    $unique_id substr($barcode166); 
        
    $qty substr($barcode22);   
        
    $query "SELECT mat_id, supplier_id, uom_id ";
        
    $query .= "FROM check_info ";
        
    $query .= "WHERE mat_id = '$item_code' AND supplier_id = '$supplier' AND uom_id = '$uom'";
        
    $result mysql_query($query);
        
    $cnt mysql_num_rows($result);
        
    $invalid 'Invalid';
        if(
    $cnt==0)
        {
            
    $str trim(preg_replace('/\s+/',' '$invalid));
            echo 
    $str;
            }
        else
        {
            
    //echo "Correct";
            
    $query_info "SELECT d.kind, m.mat_id, d.item_code, d.supplier_code, d.dspi_uom, o.uom_id, s.supplier_id, d.supplier ";
        
    $query_info .= "FROM data_upload AS d JOIN raw_material AS m ON (m.item_code = d.item_code) JOIN uom_list AS o ON (d.dspi_uom = o.uom) ";
        
    $query_info .= "JOIN supplier AS s ON (s.supplier_name = d.supplier) "
        
    $query_info .= "WHERE m.mat_id = '$item_code' AND s.supplier_id = '$supplier' AND o.uom_id = '$uom'";
        

        
    $result_info mysql_query($query_info);

        
        if(
    $row mysql_fetch_array($result_info))
        {
        
           
    // echo $po_number . "^" . $unique_id . "^" . $row["kind"] . "^" . $row["item_code"] . "^" . $row["supplier_code"] . "^" . $row["dspi_uom"] . "^" . 
           // $row["supplier"] . "^" . $qty;
           
    echo($po_number "^" $unique_id "^" $row["kind"] . "^" $row["item_code"] . "^" $row["supplier_code"] . "^" $row["dspi_uom"] . "^" $row["supplier"] . "^" $qty "^" .$barcode);
        }

        }
     }
       
    // exit;
    and getbarcode_wms.php
    PHP Code:
    <?php
    include("includes/connection.php");
    if(
    $_POST["wh"])
    {
        
    $barcode_wh $_POST['wh'];
        
    $result mysql_query("SELECT whse, row, rack, level FROM warehouse WHERE id = '$barcode_wh'");
        
        
    $cnt mysql_num_rows($result);
        
    $invalid 'Invalid';
        if(
    $cnt==0)
        {
            
    $str trim(preg_replace('/\s+/',' '$invalid));
            echo 
    $str
        }
        else
        {
        if(
    $row mysql_fetch_array($result))
        {
            echo 
    $row["whse"] . "^" $row["row"] . "^" $row["rack"] . "^" $row["level"] . "^" $barcode_wh 
        }
        }
    }
    I can't find what is the cause of that error when i type on Material Barcode also in Warehouse Barcode.

    I hope somebody can help me to resolve this error.

    Thank you so much.

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,388
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Your browser's console should be able to give you some more information about which line of JS is causing the error. Without knowing which part of the code is broken it's impossible to trace the source of the error.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •