Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:37:28+00:00 2026-05-27T21:37:28+00:00

I’ve been trying to create a button within a php page called by ajax

  • 0

I’ve been trying to create a button within a php page called by ajax function that pops up a menu when clicked for quite some time but I can’t seem to figure it out. The php page is posted under a div called cbox through an ajax method named postAll:

<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="jquery-latest.js"></script>
<script type="text/javascript">
function toggleElement(id) 
{
    var element=document.getElementById(id);
    if(element.style.display=="block")
    {
        element.style.display="none";
    }
    else
    {
        element.style.display="block";
    }
}
function postAll()
{
    if(String(window.location).indexOf("?")==-1)
    {
        var location=window.location.href;
    }
    else
    {
        var location=window.location.href.substring(0,window.location.href.indexOf("?"));
        var clength=(window.location.href.length-1)-(window.location.href.indexOf("currentpage"))-11;
        var currentpage=window.location.href.substr(window.location.href.length-clength,clength);
    }
    xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("cbox").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","dynamic.php?location="+location+"&currentpage="+currentpage,true);
    xmlhttp.send();
}

$(document).ready(function()
{
    document.getElementById("option").addEventListener("click",function(){alert("Success");});
    postAll();
});
</script>

I’ve tried using addEventListener but I’m not sure I’m using that correctly. I’ve also tried using the following code but it didn’t work either:

$("#cbox").delegate("a","click", function() {
   toggleElement('option_toggle');
});
$("#cbox").on("click", "a", function() {
   toggleElement('option_toggle');
});

For the .on method I got an uncaught type error as well.
Here’s the actual button I’m trying to get to pop up a menu:

<div id="option"><p><a href="#"><img class="select" src="cog.png"></img></a></p></div>
<div id="option_toggle" style="display:none;"> Random Text </div>

Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:37:28+00:00Added an answer on May 27, 2026 at 9:37 pm

    I can’t see the code to open a dialog in your sample.
    Anyway – I added a really small example.
    For this code, I download jquery-ui and I followed the sample for jquery dialog.

    I even added Ajax, even though there is no connection, and I wrote everything with JQuery – as a response to the comments you got.

    Here is file #1 – contains a button that invokes an Ajax call to some more content

    <button onclick="loadAjaxContent()">Load ajax content</button>
    
    
    <div id="ajaxContentContainer">
    
    </div>
    
    
    <script type="text/javascript">
        function loadAjaxContent()
        {
            $.ajax({
                url:'/Application/content',
                data:{param1:"value1"},
                success:function(result){$("#ajaxContentContainer").html(result)},
                error:function(result){$("#ajaxContentContainer").html(result.responseText)}
    
            })
        }
    </script>
    

    Now here is page #2 – which is injected into the first one. This page has another button that opens a dialog.

    <button onclick="openPopup()">open popup</button>
    
    
    <div id="dialogContent">
        this is a dialog content
    </div>
    <script type="text/javascript">
        $("#dialogContent").dialog({autoOpen:false});
        function openPopup()
        {
    
           $("#dialogContent").dialog('open');
        }
    </script>
    

    Please make sure you import all the js and css files correctly. The list of files to be imported is :

    1. jquery-ui-1.8.16.custom.css (version may vary) – this file should have an “images” folder right next to it
    2. jquery-1.6.2.min.js (version may vary)
    3. jquery-ui-1.8.16.custom.min.js (version may vary)

    You must import the “jquery-ui” file AFTER the “jquery” file. The order is important.

    This should work, or at least give you a good kick start.
    Let me know if more is needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.