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 9136543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:57:59+00:00 2026-06-17T08:57:59+00:00

I have a function, ajaxinclude() which includes the content of a page. It works

  • 0

I have a function, ajaxinclude() which includes the content of a page.
It works perfectly when written like:

<div>
     <script type="text/javascript">
          ajaxinclude("info/content/About.php")
     </script>
</div>

Now, I want a button on-click this should come.
Thus,

<button onclick="document.getElementById('aaa').innerHTML = '<script type='text/javascript'>ajaxinclude(\'info/content/About.php\');</script>">Hello</button>

But this doesn’t work.

Another method would be

<button onclick="document.getElementById('aaa').innerHTML = '<script type='text/javascript'>' + ajaxinclude('info/content/About.php') + '</script>">Hello</button>

But this doesn’t work either.

This is my ajaxinclude() function:

var rootdomain = "http://" + window.location.hostname;

function ajaxinclude(url) {
    var page_request = false

    if (window.XMLHttpRequest)
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e){
            try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e){}
        }
    }
    else
    return false
    page_request.open('GET', url, false)
    page_request.send(null)
    writecontent(page_request)
}

function writecontent(page_request){
    if (window.location.href.indexOf("http")==-1 || page_request.status==200)
    document.write(page_request.responseText)
}

How, how do I include the text on a button click?

PS: I don’t want jQuery.

  • 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-06-17T08:58:00+00:00Added an answer on June 17, 2026 at 8:58 am

    Try

    <button onclick="document.getElementById('aaa').innerHTML = ajaxinclude('info/content/About.php')">Hello</button>
    

    However I must warn that inline JavaScript is bad practice, especially like this! You can rewrite your writecontent function to accept two parameters: the page request and the ID of the target to write to.

    Your new writecontent function would be:

    function writecontent(page_request, write_target){
        if (window.location.href.indexOf("http")==-1 || page_request.status==200) {
            document.getElementById(write_target).innerHTML = page_request.responseText;
        }
    }
    

    You’ll need to pass the ID of the write target there, and since you’re calling writecontent from ajaxinclude, you’ll need the parameter there too:

    function ajaxinclude(url, write_target) {
        // ...
        writecontent(page_request, write_target);
    }
    

    And in the button:

    <button onclick="ajaxinclude('info/content/About.php', 'aaa')">Hello</button>
    

    Optionally continuing…

    Even better would be binding the click action to the button instead of using onclick. This would be easier with jQuery, but since you explicitly stated you do not want to use jQuery, you can also do it using addEventListener() in your JavaScript:

    document.getElementById('thisbutton').addEventListener('click', function(){ajaxinclude('info/content/About.php', 'aaa')}, false);
    

    And that would change the button to:

    <button id='thisbutton'>Hello</button>
    

    Read more about event listeners at the Mozilla Developer Network.

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

Sidebar

Related Questions

i have function <script type=text/javascript> $(function () { $(#search).click(function() { var text = $(#searchText).val();
I have function some_func_1 which will create an object of type some_type and will
I have function in Javascript which works fine using prototype. The function is used
I have function which append div (help icon) after all element with .help class.
i have function which is something like this function multiple_delete($entity1,$entity2,$entity2) { $query = SELECT
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
Inside my Controller i have function that runs after user clicks on item, which
I have function which is removing and adding class into input tag, i want
I have function which gets a Seq[_] as an argument and returns an immutable

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.