piotr.linski 0 Newbie Poster

I managed to get a certain PHP variable ($length) that contains the length of a message (stored in a MYSQL-database) to get passed to a javascript variable (var = length) in order to let javascript decide whether or not to show a certain marquee on a HTML-page.

Initially I have used the javascript document.write statement to get the output displayed. However, using document-write "kills" the present HTML-page instead of integrating the marquee content into that HTML-page and keeping that HTML-page intact .

So I have made some changes and the code I have sofar is the following:

<script type="text/javascript">
var length = 0;
var message = 0;
$(document).ready(function() {

$.ajax({
    type: "POST",
    url: "https://www.transitum.org/linski_nach/check3.php",
    dataType: "json",
    data: { length: length },
    success: function(data, textStatus, jqXHR) {
      if (textStatus === "success" && jqXHR.readyState === 4) {
        length = JSON.parse(data); // Set the global variable
        if (length  > 1) { 
                    message = { item:"<iframe src='https://www.transitum.org/linski_nach/test3.php' width='100%' height='55' scrolling='no' frameBorder='no' </iframe>"  };
        } else { 
                    message = { item:"<table><td>no message available</td></table>" };
        }
                message.showDetails = displayDetails;
                message.showDetails();
      } else {
        // Do nothing...
      }
    }
  });
    function displayDetails() {
        document.getElementById("details").innerHTML = this.item;
    }
});

</script> <p id="details">empty</p>

At present the result of the script is that I always get displayed "empty" in the HTML page.
This result can be seen via this fiddle-link.
where what really should happen is that:

  • a certain marquee gets displayed within an HTML-page, when var length > 1
  • and if var length <=1 then "no message available" shoul be displayed.

Any suggestions how to solve would be highly appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.