#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    41
    Rep Power
    3

    Problem in popup page with document.getElementById


    Hi!

    Good day!

    I have php file called: fab_spv_reports.php with a textbox : section_name and in that section name I have javascript function that display a table of process name/compound type with designated output and reject textboxes and it came from get_fab_spv_process_reject_list.php. On that textboxes when I click it has a pop up will displayed.

    When running the table page by itself (get_fab_spv_process_reject_list.php), the popup works fine, but when the table is loaded into into the main page (fab_spv_reports.php) as an object, the popup doesn't work.


    here is my code:
    fab_spv_reports.php
    Code:
    <?php
     error_reporting(0);
     session_start();
     date_default_timezone_set("Asia/Singapore");
      
      include('connection.php');
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Supervisor's Shift Report </title>
    <link rel="stylesheet" type="text/css" href="op_report.css" />
    <link rel="stylesheet" type="text/css" href="calendar.css" />
    
    <script type="text/javascript" src="jquery.js"></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
    
    <script type="text/javascript">
    //----auto complete section name---//
    
    $().ready(function() {
        $("#section_name").autocomplete("get_section_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#section_name").result(function(event, data, formatted) {
            $("#section_id").val(data[1]);
        });  
         
    });
    //------AJAX-----//
    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;
                        }
                    }
                }
            }
    
    //-----get reject---//
    function getmat()
            {
               //  if (window.event.keyCode==13 || window.event.keyCode==10) {
                divid = "op_output_fieldset";
                var url = "get_fab_spv_process_reject_list.php";
                var str = "id=" + document.getElementById("section_name").value;
                var xmlHttp = AJAX();
                xmlHttp.onreadystatechange =  function(){
                if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){
                   // document.getElementById(divid).innerHTML=loadingmessage;
                    }
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                        var jsonart = xmlHttp.responseText;
                        document.getElementById(divid).innerHTML = jsonart;
                        
                        }
                    }
                }
                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);
              
           // }
            }
            
    </script>
    </head>
    <body onload=document.getElementById("section_name").focus();>
    <form name="operator_report" action="<?php echo $PHP_SELF; ?>" method="post" autocomplete="off">
    <div id="operators_report">
    <fieldset>
    <legend><h1>Supervisor's Shift Report</h1></legend>
    <table>
    <tr>
    <td>Section:</td>
    <td><input type="text" name="section_name" id="section_name" value="<?php echo $section_name; ?>" size="30" onkeydown="jumpnext('supervisor');getmat();"></td>
    <td>Supervisor:</td>
    <td><input type="text" name="supervisor" id="supervisor" value="<?php echo $supervisor; ?>" size="30" onkeydown="jumpnext('process_date');"></td>
    </tr>
    </table>
    
    </fieldset>
    </div>
    <input type="hidden" name="section_id" id="section_id" value="" />
    <div id="op_output_fieldset">
    </div>
    </form>
    </body>
    </html>
    get_fab_spv_process_reject_list.php
    Code:
    <?php
    ob_start();	 
    session_start();
    include "connection.php";
    
    //$section_name = 'Compounding';
    $section_name = $_POST["id"];
    //if($_POST["id"])
    if(isset($section_name))
    {  
        
       //Build display data BEFORE output
        $display = "";
        
    //-----end of displaying reject name---// 
    
     //  $display .= "<form action=\"\" method=\"post\">"; 
       $display .= "<div id='spv_fieldset'>"; 
       $display .=  "<fieldset>";
       $display .= "<legend style='font-size:36px;'> Supervisor's Output and Reject</legend>";
       $display .= "<table>";
       
       $display .= "<tr>";
       $display .= "<th>Process</th>";
    
        //query to select reject acronym  
        $sql = "select p.process_name, p.process_id FROM process_list AS p JOIN section_list AS s ON (p.section_id = s.section_id)
        where s.section_name LIKE '%" .$section_name. "%'";
        $rsd = mysql_query($sql);
        while($rs = mysql_fetch_assoc($rsd)) {
            $process_name[] = $rs['process_name'];
            $process_id[] = $rs['process_id'];
        }
        
        if(!isset($process_name) || isset($process_name) && empty($process_name)){
            $display .= "";
        }else{   
            //display reject acronym as header               
            foreach ($process_name as $k => $process_name_v){
    		$process_id_vv = $process_id[$k];   
                $display .= "<th style='border:none;' colspan='2'>
    			<input type='hidden' name='process_id[]' value='$process_id_vv' style='border:none;background-color: transparent;text-align:center; font-weight: bold;' size='15' />
    			<input type='text' name='process_name[]' value='$process_name_v' style='border:none;background-color: transparent;text-align:center;color: #fff; font-weight: bold;' size='15' />
    			</th>";
            }
            
                    //display reject acronym as header               
            foreach ($process_id as $process_id_vv){   
               // $display .= "<input type='hidden' name='process_id[]' value='$process_id_vv' style='border:none;background-color: transparent;text-align:center; font-weight: bold;' size='15' />";
            }
            
            
            $display .= "</tr>";  
        } 
    
    
       $display .= "<tr>";
       $display .= "<th>Compound</th>";
       foreach($process_id AS $process_ii) {
       $display .= "<th>Output</th>";
       $display .= "<th>Reject</th>";
       }
        //query select compound_type
        $sql_comp = "SELECT compound_id, compound_type FROM compound_list ORDER BY compound_type ASC";
        $res = mysql_query($sql_comp);
    
        if(mysql_num_rows($res)){
            
            while($comp = mysql_fetch_assoc($res)){    
            
            $compound_type = $comp['compound_type'];
            $compound_id   = $comp['compound_id'];   
                
            $display .= "<tr>";
    
                //---display compound_type
                $display .= "<td style='border:none;'>
                <input type='text' name='compound_type[]' value='$compound_type' style='border:none;' size='10' />
                <input type='hidden' name='compound_id[]' value='$compound_id' />
                </td>";
                //---input box for output
                
                //----i used foreach to loop textbox in every reject acronym.
                foreach($process_id AS $process_i) {
                  //----in this textboxes display the popup window using onkeyup to input the total then after click the submit button from popup the total will be displayed on the textbox.  
                  $output_value = (isset($_SESSION['output']) && array_key_exists($process_i,$_SESSION['output']) && array_key_exists($compound_id,$_SESSION['output'][$process_i]) ? "{$_SESSION['output'][$process_i][$compound_id]}" :'');
    			  $display .= "<td style='border:none;'>
    			  <input type='hidden' name='output.$process_i.$compound_id' value='output.$process_i.$compound_id' id=\"output.$process_i.$compound_id\" />
    			  <input type='text' name='output[$compound_id][$process_i][]' value='$output_value' size='7' id=\"o.$process_i.$compound_id\"  onclick=\"var val = document.getElementById('output.$process_i.$compound_id').value; child_open(val);return false\" />
                 
    			  </td>"; 
                  $reject_value = (isset($_SESSION['reject']) && array_key_exists($process_i,$_SESSION['reject']) && array_key_exists($compound_id,$_SESSION['reject'][$process_i]) ? "{$_SESSION['reject'][$process_i][$compound_id]}" :'');
                  $display .= "<td style='border:none;'>
    			  <input type='hidden' name='reject.$process_i.$compound_id' value='reject.$process_i.$compound_id' id=\"reject.$process_i.$compound_id\" />
    			  <input type='text' name='reject[$compound_id][$process_i][]' value='$reject_value' size='7' id=\"r.$process_i.$compound_id\"  onclick=\"var val = document.getElementById('reject.$process_i.$compound_id').value; child_open(val);return false\" />
    			  </td>";
              
                }
                
                $display .= "</tr>";
            }
        }
    }
     $display .= "</table>
    </fieldset>
    </div>"; 
     //$display .= "<input type='submit' name=\"save_values\" value=\"Save\" />
     //</form>"; 
    ?>
    
    <head>
    <title> Supervisor's Output and Reject</title>
    <script type="text/javascript">
    
        var popupWindow=null;
    
        function child_open(val){
            popupWindow =window.open('popup.php' + "?val=" + val,"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
        }
    
        function parent_disable() {
            if(popupWindow && !popupWindow.closed)
                popupWindow.focus();
        }
    </script>
    </head>
    <body>
    <?php
        if(isset($display)){
            echo "$display";
        }	
    ?>
    </body>
    popup.php
    Code:
    <?php
    if(isset($_GET['val'])){
    	$parts = explode(".",$_GET['val']); 
    	$type = $parts[0]; 
    	$process_id = $parts[1]; 
    	$compound_id = $parts[2];	
    }
    ?>
    
    
    <html>
    <title>Supervisor's Report</title>
    <head>
    <script type="text/javascript">
    function compute() {
        var n1 = document.getElementById("n1").value;
        var n2 = document.getElementById("n2").value;
        var total = document.getElementById("total").value = n1 + n2 ;
    }
      
      
    function compute_(oText){
        if (isNaN(oText.value)) //filter input
    {
    alert('Numbers only!');
    oText.value = '';
    }
    var field, val, oForm = oText.form, total = a = 0;
    for (a; a < arguments.length; ++a) //loop through text elements
    {
    field = arguments[a];
    val = parseFloat(field.value); //get value
    
    if (!isNaN(val)) //number?
    {
    total += val; //accumulate
    }
    }                                                                                 
    oForm.total.value = total.toFixed(2); //out
    }  
    
    function jumpnext(nextcontrol)
        {
       if(window.event.keyCode==13 || window.event.keyCode==10)
            document.getElementById(nextcontrol).focus();
        }  
    </script>
    </head>
    <body onLoad="document.getElementById('n1').focus();"> 
    
    
    <form action="popup_processing.php" method="post">
    <input type="hidden" name="type" value="<?php echo $type;?>" />
    <input type="hidden" name="process_id" value="<?php echo $process_id;?>" />
    <input type="hidden" name="compound_id" value="<?php echo $compound_id;?>" />
    <div>
    <table>
    <tr>
    <td><input type="text" name="n1" id="n1" value="" onkeyup="compute_(this, n2);jumpnext('n2');" ></td>
    <td><input type="text" name="n2" id="n2" value="" onkeyup="compute_(this, n1);;"></td>
    </tr>
    <tr>
    <tr>
    <td colspan="2"><input type="text" name="total" id="total" value="" size="45"></td>
    </tr>
    </tr>
    </table>
    <input type="submit" name="submit" id="submit" value="Submit" >
    </div>
    </form>
    </body>
    </html>
    On testing.run the fab_spv_reports.php try to type Com on section then there is a auto suggest displayed, choose Compounding useing arrow down key then press enter key.

    Try to click in any textboxes on supervisors output and reject you will get an object expected error.

    But when you run directly using get_fav_spv_process_reject_list the popup will display after click on any textboxes.

    I attached the sample screenshot and database
    I hope somebody can help me on this.

    Thank you so much.
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo