Jump to content

Recommended Posts

After I added the div tab, the AJAX sub-menu is not working anymore. I am stuck here for whole day.

<div class="tab">
	<button class="tablinks" onclick="openProgram(event, 'add_item')" id="defaultOpen">Add Item</button>
	<button class="tablinks" onclick="openProgram(event, 'list_item')">List Items</button>
</div>

<!-------------------------------------------------------------------------------------------------------------------------------->
<div id="add_item" class="tabcontent">


<div id="list_item" class="tabcontent">
...
//not working here
echo '<select name="listcategory" onchange="showsubcat(this.value)">';
foreach ($categoryRows as $categoryRow){
	echo '<option value="' . $categoryRow['id'] . '">' . $categoryRow['category_name'] . '</option>';
}
echo '</select>';
echo '<div id="subcatchooser"><b>No Subcategory</b></div>';
//not working here
<script>

function showsubcat(str) {
    if (str.length == 0) { 
        document.getElementById("subcatchooser").innerHTML = "";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("subcatchooser").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET", "ajax.php?action=showsubcat&parent_id=" + str, true);
        xmlhttp.send();
    }
}

</script>
Link to comment
https://forums.phpfreaks.com/topic/303718-ajax-sub-menu-not-working-in-div-tab/
Share on other sites

  • 1 month later...

I would hazard a guess that it's probably got something to do with the this keyword. You don't have the rest of the context for that code, so there is no way to tell what this is.

 

So this.value is likely not what you're expecting it to be

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.