Skip to content Skip to sidebar Skip to footer

Changing The Contents Of A Div Using A Dropdown, Javascript And Php

I'm a noob but will gladly take some stick for it if you help me find the answer ;) I have a list of categories in an array $cat_array. I want to build a select drop-down so that w

Solution 1:

n00b! OK, stick out of the way :-)

You are passing 'facebook-midcut' to your categoryAjaxData() function. Does the eventual DOM lookup know whether you mean the div with the id or the div with that class? If you're using a libray like jquery it wouldn't know which node you mean without further classification. I would guess you're trying to get the one with the class so you can't use getElementById().

You may also want to add a slash to the start of 'includes/fancount.php'. Adding a slash to the start of this means the path will reference from your site's document root rather than from your current location within the site.

Are you using some kind of js library? It would be useful to see your ajaxData function as the problem could very well be there.

A quick tip for you. Learn when to use single and double quotes in PHP. It will make your code simpler and faster. echo "<div id=\"facebook-midcut\">"; could be written as echo '<div id="facebook-midcut">';

I'll check back to see if you've updated your post with the info I've asked for then I can give you more help.

UPDATE:

I assume the function DescriptionstateChanged(div) is where the actual updating of the div happens but you never pass it the xmlHttp object. Is this meant to be a global object? If not then you definitely need to pass it to the DescriptionstateChanged() function and I would recommend that it shouldn't be a global object anyway. If the DescriptionstateChanged() function is where the actual updating of the div takes place can you post this function too?

Solution 2:

You may want to change this:

echo '<select class="selbox" onchange="categoryAjaxData("facebook-midcut","/includes/fancount.php",this.value);">';

with this:

echo'<select class="selbox" onchange="categoryAjaxData(\'facebook-midcut\',\'/includes/fancount.php\',this.value);">';

Note how the output of your code would be invalid HTML:

<selectclass="selbox" onchange="categoryAjaxData("facebook-midcut","/includes/fancount.php",this.value);">

Post a Comment for "Changing The Contents Of A Div Using A Dropdown, Javascript And Php"