Solved

PHP AJAX is null or not an object ..

Posted on 2008-10-16
8
561 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 50

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 50

Expert Comment

by:Steve Bink
ID: 22772851
Where in the code are you getting the error?  
0
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 50

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 50

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now