Jump to content

Firefox printing problems when putting html form through ajax


willrockformilk

Recommended Posts

hi guys.

 

the subject says it all. im writing an edit page for a phone book where users can remove entry's and change phone numbers from users. i have a seperate page for editing use information so lets focus on the phone numbers.

 

the problem is. i output my code in php on the ajax page then send the data back to the search page through ajax. it works like a charm on chrome and IE. but it wont print the elements inside of the <form> tag. i put the inputs on the outside of the <form> tag and it prints them out. but when you click them nothing happens.

 

 

oh and i know on my ajaxedit page there is alot of unused code at the bottom. ill take care of that later.

 

here is my code:

 

editnum.php

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
<head>
<script type="text/javascript">

var ajaxObject = false;
// this is our object which gives us access
// to Ajax functionality

function doAjaxQuery(url) {

        ajaxObject = false;

    if (window.XMLHttpRequest) { // if we're on Gecko (Firefox etc.), KHTML/WebKit (Safari/Konqueror) and IE7
       
        ajaxObject = new XMLHttpRequest(); // create our new Ajax object

        if (ajaxObject.overrideMimeType) { // older Mozilla-based browsers need some extra help
            ajaxObject.overrideMimeType('text/xml');
        }
   
       
    }
    else if (window.ActiveXObject) { // and now for IE6
            try {// IE6 has two methods of calling the object, typical!

            ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");
            // create the ActiveX control


        } catch (e) { // catch the error if creation fails

            try { // try something else

            ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
            // create the ActiveX control (using older XML library)


            } catch (e) {} // catch the error if creation fails
        }
    }

        if (!ajaxObject) { // if the object doesn't work

            // for some reason it hasn't worked, so show an error

        alert('Sorry, your browser seems to not support this functionality.');

        return false; // exit out of this function
        }

   
        ajaxObject.onreadystatechange = ajaxResponse; // when the ready state changes, run this function

    // DO NOT ADD THE () AT THE END, NO PARAMETERS ALLOWED!

    ajaxObject.open('GET', url, true); // open the query to the server

        ajaxObject.send(null); // close the query

    // and now we wait until the readystate changes, at which point
    // ajaxResponse(); is executed

    return true;

    } // end function doAjaxQuery

function ajaxResponse() { // this function will handle the processing

    // N.B. - in making your own functions like this, please note
    // that you cannot have ANY PARAMETERS for this type of function!!
   
    if (ajaxObject.readyState == 4) { // if ready state is 4 (the page is finished loading)

        if (ajaxObject.status == 200) { // if the status code is 200 (everything's OK)

            // here is where we will do the processing
            
            var divContent = ajaxObject.responseText;
            document.getElementById('resultsarea').innerHTML = divContent; 






        } // end if

        else { // if the status code is anything else (bad news)

            alert('There was an error. HTTP error code ' + ajaxObject.status.toString() + '.');
            return; // exit

        }

    } // end if

    // if the ready state isn't 4, we don't do anything, just
    // wait until it is...


} // end function ajaxResponse

</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pinecrest Supports and Services Center - Phone Book</title>
</head>
<body
style="color: rgb(255, 255, 255); background-color: rgb(99, 118, 153); direction: ltr;"
alink="#ffffff" link="#ffffff" vlink="#ffffff">
<div style="text-align: center;">
<br><br><img src='../seal.png'><br><br><br>
<h1>Pinecrest Supports and Services Center - Phone Book</h1>
<br>
For any changes that need to be made please e-mail them to: [email protected]
<br>
<br>
<a href=phonebookedit.php>Back to edit page</a>
<br>
<br>
<table
style="width: auto; height: auto; text-align: center; margin-left: auto; margin-right: auto; font-family: Calibri;"
border="0" cellpadding="0" cellspacing="0">
  <tr>
<td style="background-color: rgb(58, 68, 90)">
<h3>Phone Book Search:</h3>
</td>
</tr>
<tr>
<td>
<table
style="width: auto; height: auto; text-align: center; margin-left: auto; margin-right: auto; font-family: Calibri;"
border="0" cellpadding="2" cellspacing="2"> 


<tr>
<td style='background-color: rgb(58, 68, 90)'>Phone:</td><td style='background-color: rgb(58, 68, 90)'><input type="text" name="phone" id="phone" value="" onkeyup="doAjaxQuery('ajaxedit.php?dept=0&phone=' + document.getElementById('phone').value);"/></td>
</tr>


</table>
</tr>
</td>
</table>
<button onclick="doAjaxQuery('ajaxedit.php?dept=0&phone=' + document.getElementById('phone').value);">Submit</button>



<br />
<br />

<div width=300 id="resultsarea" align="center"></div>

</body>
</html>

 

 

ajaxedit.php

 

<?php

// Error Display

ini_set('display_errors', 1); 
ini_set('log_errors', 1); 
ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); 
error_reporting(E_ALL & ~E_NOTICE);

//Connect to Server and Select Database

$con = mysql_connect("localhost","root","*****");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("phonedirectory", $con);



									  
// Start script

   		 	   	// security

   		 	    $fn = mysql_real_escape_string($_GET['fname']);
   		 	    $ln = mysql_real_escape_string($_GET['lname']);
   		 	    $ph = mysql_real_escape_string($_GET['phone']);

   		 	    
   		 	    
			// queries

                $queryphone = "SELECT * FROM phoneassignment WHERE empphonenum = '{$ph}'";
                $queryfirstname = "SELECT * FROM employee where empfname LIKE '%{$fn}%'";
                $querylastname = "SELECT * FROM employee WHERE emplname LIKE '%{$ln}%'";
                $querydepartment = "SELECT * FROM employee WHERE empdept = '$_GET[dept]' ORDER BY emplname";
                
                
                
                //loading array into var
                
                $matchedphone = mysql_query($queryphone) or die(mysql_error());
                $matchedfirstname = mysql_query($queryfirstname) or die(mysql_error());
                $matchedlastname = mysql_query($querylastname) or die(mysql_error());
                $matcheddepartment = mysql_query($querydepartment) or die(mysql_error());

               
                
                
                //if data was entered into field then it will search for it
                
                if (mysql_num_rows($matchedphone) != 0)
                    searchphone($matchedphone);
                if (mysql_num_rows($matchedfirstname) != 0)
			   if ($fn != "")    
                	searchfirstname($matchedfirstname);	
                if (mysql_num_rows($matchedlastname) != 0)
                   if ($ln != "")
                	searchlastname($matchedlastname);	
			if (mysql_num_rows($matcheddepartment) != 0)
			   if ($_GET['dept'] != "0")
			    searchdepartment($matcheddepartment);

                	
                
                
                // Search Functions
                
                	
                function searchphone($resultsphone)
                {
                
			//echo "phone";





                echo "<table style='text-align: center; margin-left: auto; margin-right: auto; font-family: Calibri;'border='0' cellpadding='2' cellspacing='2'>";
                echo "<tr>";
                echo "<th style='background-color: rgb(58, 68, 90)'></th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>First Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Last Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Department</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Phone</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'></th>";
                echo "</tr>";
                
                while($tablephone = mysql_fetch_array($resultsphone))
                	{
                	 	   $empassign = $tablephone['EmpAssign'];
                	 	   $phone = $tablephone['EmpPhoneNum'];

					   	$queryphone = "SELECT * FROM phonenumber";
                  	 	 	$resultsallphone = mysql_query($queryphone) or die(mysql_error());
                	
                             $queryemployee = "SELECT * FROM employee WHERE empnum = '$empassign'";
                             $resultsemployee = mysql_query($queryemployee) or die(mysql_error());
                
                                    while($tableemployee = mysql_fetch_array($resultsemployee))
                                    	{
                
                                    	 	   $emplname = $tableemployee['EmpLName'];
                                    	 	   $empfname = $tableemployee['EmpFName'];
                                    	 	   $empdept = $tableemployee['EmpDept'];
                                    	 	   
                                    	echo "<tr>";
                                    		
										echo "<form action='phonebookremoveentry.php' method='get' enctype='multipart/form-data'>";
										echo "<td style='background-color: rgb(58, 68, 90)'><input type='hidden' name='remove' value='" . $empassign . "'></input><input type='hidden' name='phone' value='" . $phone . "'></input><input type=submit value='Remove'></input></td>";
										echo "</form>";                                    		
                                    		
                                    		
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empfname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $emplname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empdept . "</td>";
										echo "<form action='updatenum.php' method='get' enctype='multipart/form-data'>";											                                    		
										echo "<td style='background-color: rgb(58, 68, 90)'><input type='hidden' name='empid' value='" . $empassign . "'></input><select name='number'><option value='" . $phone . "'>" . $phone . "</option>";
											 	  while ($nums = mysql_fetch_array($resultsallphone))
											 	  {
											 	  $number = $nums['PhoneNumber'];
											 	  echo "<option value='" . $number ."'>" . $number . "</option>";
											 	  }
										echo "</select></td>";
										echo "<td style='background-color: rgb(58, 68, 90)'><input type=submit value='Change Number' /></form>";
                                       	echo "</tr>";
                                    	
                                    	}
                	 }
                

                                    	echo "</table>";
                
                }
                
                





































			function searchfirstname($resultsfirstname)
                {
                
			//echo "fn";
                echo "<table style='text-align: center; margin-left: auto; margin-right: auto; font-family: Calibri;'border='0' cellpadding='2' cellspacing='2'>";
                echo "<tr>";
                echo "<th style='background-color: rgb(58, 68, 90)'>First Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Last Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Phone</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Department</th>";
                echo "</tr>";

                while($row = mysql_fetch_array($resultsfirstname))
                	{
                
                           $empnum = $row['EmpNum']; 
                           $emplname = $row['EmpLName'];
                           $empfname = $row['EmpFName'];
                           $empdept = $row['EmpDept'];
                
                	
                             $queryemployee = "SELECT * FROM phoneassignment WHERE empassign = '$empnum'";
                             $resultsemployee = mysql_query($queryemployee) or die(mysql_error());
                
                                    while($row = mysql_fetch_array($resultsemployee))
                                    	{
                						 	   $phone = $row['EmpPhoneNum'];
                 
                                    	   
                                    	   
                                    	echo "<tr>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empfname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $emplname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $phone . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empdept . "</td>";
                                    	echo "</tr>";
                                    	
                                    	}
                	 }
                }
                
                function searchlastname($resultslastname)
                {
                
			//echo "ln";
                echo "<table style='text-align: center; margin-left: auto; margin-right: auto; font-family: Calibri;'border='0' cellpadding='2' cellspacing='2'>";
                echo "<tr>";
                echo "<th style='background-color: rgb(58, 68, 90)'>First Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Last Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Phone</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Department</th>";
                echo "</tr>";

                while($row = mysql_fetch_array($resultslastname))
                	{
                
                           $empnum = $row['EmpNum']; 
                           $emplname = $row['EmpLName'];
                           $empfname = $row['EmpFName'];
                           $empdept = $row['EmpDept'];
                
                	
                             $queryemployee = "SELECT * FROM phoneassignment WHERE empassign = '$empnum'";
                             $resultsemployee = mysql_query($queryemployee) or die(mysql_error());
                
                                    while($row = mysql_fetch_array($resultsemployee))
                                    	{
                						 	   $phone = $row['EmpPhoneNum'];
                 
                                    	   
                                    	   
                                    	echo "<tr>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empfname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $emplname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $phone . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empdept . "</td>";
                                    	echo "</tr>";
                                    	
                                    	}
                	 }
                }
                
                function searchdepartment($resultsdepartment)
                {

			//echo "dp";
                echo "<table style='text-align: center; margin-left: auto; margin-right: auto; font-family: Calibri;'border='0' cellpadding='2' cellspacing='2'>";
                echo "<tr>";
                echo "<th style='background-color: rgb(58, 68, 90)'>First Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Last Name</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Phone</th>";
                echo "<th style='background-color: rgb(58, 68, 90)'>Department</th>";
                echo "</tr>";


                while($row = mysql_fetch_array($resultsdepartment))
                {
                
                           $empnum = $row['EmpNum']; 
                           $emplname = $row['EmpLName'];
                           $empfname = $row['EmpFName'];
                           $empdept = $row['EmpDept'];
                
                	
                             $queryemployee = "SELECT * FROM phoneassignment WHERE empassign = '$empnum'";
                             $resultsemployee = mysql_query($queryemployee) or die(mysql_error());
                
                                    while($row = mysql_fetch_array($resultsemployee))
                                    	{
                						 	   $phone = $row['EmpPhoneNum'];
                 
                                    	   
                                    	   
                                    	echo "<tr>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empfname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $emplname . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $phone . "</td>";
                                    		echo "<td style='background-color: rgb(58, 68, 90)'>" . $empdept . "</td>";
                                    	echo "</tr>";
                                    	
                                    	}
                	 }
			 }


?>

 

 

 

<form action='phonebookremoveentry.php' method='get' enctype='multipart/form-data'>
<td style='background-color: rgb(58, 68, 90)'>
<input type='hidden' name='remove' value='77'></input>
<input type='hidden' name='phone' value='3008'></input>
<input type=submit value='Remove'></input></td></form>
<td style='background-color: rgb(58, 68, 90)'>Pamela</td>
<td style='background-color: rgb(58, 68, 90)'>Dorty</td>
<td style='background-color: rgb(58, 68, 90)'>Staff Training</td>
<form action='updatenum.php' method='get' enctype='multipart/form-data'>
<td style='background-color: rgb(58, 68, 90)'>
<input type='hidden' name='empid' value='77'></input>
<select name='number'><option value='3008'>3008</option>
<option value='2000'>2000</option>

 

then a couple thousand options for phone numbers.  but it loops through like this each result it gets.

 

remember now. the code works like a charm in IE and chrome. just not firefox.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.