?
Solved

PHP AJAX is null or not an object ..

Posted on 2008-10-16
8
Medium Priority
?
569 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

616 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