?
Solved

PHP AJAX is null or not an object ..

Posted on 2008-10-16
8
Medium Priority
?
566 Views
Last Modified: 2012-05-05
Hi  

I am want to fill a up the listbox with some values that i have in my db
every thing works well exepnt the part when i try to get the div to set the values that i want from the db

it tell me is null or not an object ..


Any help

Thanks


div.txt
0
Comment
Question by:dentrita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 51

Expert Comment

by:Steve Bink
ID: 22747121
At what point does the code fail?
0
 
LVL 1

Author Comment

by:dentrita
ID: 22772226
when i click the first combo box becose i will populate the next combobox depending on the selected item on the first one
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 22772851
Where in the code are you getting the error?  
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 1

Author Comment

by:dentrita
ID: 22782120
Hi

When i chanche the selection of this combobox

<select name='select' class='style1' style='width:200px'  onchange='showFiles(this.value,document.form1.valorArchivo);'>

I get a jave script error that said is null or not an object

if you check the funtion showFiles
function showFiles(str, val)
{
......
            if(ajaxRequest.readyState == 4)
            {
HERE I GET THE ERROR IS NULL OR NOT AN OBJECT

                  val.innerHTML=ajaxRequest.responseText;
            }
      }

val is the div that i create on the code

there is the code where i create the div

$resultNavegacion .= "<div name='valorArchivo'><option value='0'>Selecionar archivo</option></div></td></tr><tr><td align='left' valign='top'>&nbsp;</td><td><input name='borrar' type='submit' id='borrar' value='Ok'></td></tr>";

What i what to do is this

in my site i have 2 combobox
on the fisrt one i am loading the users
on the second one i want to load on the combobox the names of the files of the selected user on the first user


....
}
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 22785753
Use the open method, *then* set the onreadystatechange property:


	// Create a function that will receive data sent from the server
	ajaxRequest.open("GET", "getFiles.php?id="+str, true);
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById("valorArchivo").innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.send(null); 

Open in new window

0
 
LVL 1

Author Comment

by:dentrita
ID: 22789879
Hello

the ajaxRequest.onreadystatechange = function() it was on my code
i add this
document.getElementById("valorArchivo").innerHTML=ajaxRequest.responseText;
to my code and the error still
i will atach a screen shot of the error

Untitled-1.jpg
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 22789951
That will be because you forgot to create a div with that id.  I see in your code where you reset the value of $resultNavegacion several times.  In some of the assignments, there is no evidence of that div.  Go back and make sure that the div will ALWAYS be present.

Instead of dynamically creating the div declaration in a PHP variable, the better option is to dynamically create the div's contents, then dump it into a static HTML div.  That way, if you ever have to change the variable, you know you do not have to recreate the declaration each time.  Example:
<?
// instead of this
$mydiv = "<div id=\"stuff\">stuff</div>";
// if I redefine the variable now, I'll lose the declaration
$mydiv = "stuff2";  
echo $mydiv;
 
// use this
$mydiv = "stuff";
// this second definition will not affect the div declaration
$mydiv = "stuff2";
?>
<div id="stuff"><?=$mydiv;?></div>

Open in new window

0
 
LVL 1

Accepted Solution

by:
dentrita earned 0 total points
ID: 22798126
hi routinet
Thaks for ypur help
i found the problem
the problem was that i declare the div inside the select box and always give me the error
but when i take out the div from insade the select box it works beatifully

on your last coment you said that i the value of $resultNavegacion several times In some of the assignments, there is no evidence of that div. becouse if you check when i need the div is when i am goin to delete the file  but when i will add a file i dont need the div

the problem was the div is inside the select box

thaks a lot

Dentrita
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question