When I hit the button in my program the button does not work. How do I get the message to point to this url "http://mweisfeld.1upware.com/joke.txt" when I hit the button? Thanks



    <title>Ajax Joke of the Day Application</title>

    <script language = "javascript" type = "text/javascript">

      var Request = false;

      if (window.XMLHttpRequest) {
        Request = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        Request = new ActiveXObject("Microsoft.XMLHTTP");

      function retrieveJoke(url, elementID) {

        if(Request) {

          var RequestObj = document.getElementById(elementID);

          Request.open("GET", url);

          Request.onreadystatechange = function()
            if (Request.readyState == 4 && Request.status == 200) {
                RequestObj.innerHTML = Request.responseText;






    <H1>Where do bees go when they get married?</H1>

      <input type = "button" value = "Fetch Answer"
        onclick = "retrieveJoke('joke.txt', 'DivTarget')">

    <div id="DivTarget"> </div>



Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

8 Years
Discussion Span
Last Post by mroberts50

if you want the browser to actually navigate to joke.text then change your form to:

<form method="post" action="joke.txt">
      <input type = "submit" value = "Fetch Answer">

Thanks Hielo, it worked but if I may. How do I get the response from when I hit the button to appear on the same page as the button, instead of opening in another window?


Thanks Heilo! Yes, and no, the response when you click the fetch button "On a honeymoon" opens in another window, I want the answer to appear under the fetch button like this:

Where do bees go on when they get married?

(Fetch Button)

On a honeymoon(Answer)

(I want this answer "On a honeymoon" to appear under the fetch button after you click it, not in another window if possible. Any suggestions?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.