Jump to content

chibineku

Members
  • Posts

    1,278
  • Joined

  • Last visited

Posts posted by chibineku

  1. Well, it sort of works, but not as expected: the output field is updated when the second field loses focus, which I could have called onblur and not onchange. Final thing to try: change the event to onkeyup. I've tried it and this works as you want.

  2. My friend and his wife have a daughter who is 18 months old and I could really see the toll it took on him. I don't see him that often, maybe every 2 weeks, and each time I saw him for the first year or so he looked more tired than last time. She's adorable though, and he has recovered now. She's the first person I've ever known from day one. I see why grandparents like being grandparents - you get to play and leave the hard work up to someone else.

  3. The word document refers to the document object, which lets you access the elements of the DOM (document object model) from within scripts, for example it contains references to every div, paragraph, image, etc. and lets you select them by using a variety of methods, such as getElementsByName() or images[], which returns an array of all the images in the page. Watch this space for better, fuller explanations from the pros.

  4. Nope, that's not how it works. On the page that contains the div to hold the breaking news, you put the script I wrote. When breaking-news.php prints $news_array, that array is the parameter 'data', here:$.get('breaking-news.php', {}, function(data) {//either process the return data or stick it straight in its placeholder div$('breaking-news').html(data);});If you post the entirety of the original breaking-news.php and any other page from your site on which you want the breaking news to be displayed, I'll show you.

  5. AJAX works by sending data to, and receiving data from, a PHP script that is hosted on your server but which is not part of the current document. PHP is processed before HTML and JavaScript, as I'm sure you know. In an AJAX function, we cause the PHP script to run on the server and have the PHP send data back to the page.So you enter the AJAX script in the page in which the breaking news will appear, and task breaking-news.php with the job of fetching the news from the database and sending that data.For example, your breaking-news.php script might look like:

    <?phpinclude_once("db_connection.php");doDB();$sql = "SELECT * FROM news SORT BY date DESC LIMIT 1"; //so we fetch only the newest article$res = mysqli_query($conn, $sql) or die("Mysqli error: ".mysqli_error($conn));if(mysqli_num_rows($res) > 0) {$info = mysqli_fetch_assoc($res);$heading = $info["heading"];$body = $info["body"];echo "<h2>$heading</h2><p>$body</p>";}?>

    The ajax function on any pages on which you want the breaking-news div to be updated will cause this script to run and receive the formatted heading and body, and display it in the div. So, example-page.html might look like:

    <html><head><title>Some Title</title><script type="text/javascript" src="jquery.js"></script><script type="text/javascript">function news() {$.get('breaking-news.php', {}, function(data) {//either process the return data or stick it straight in its placeholder div$('breaking-news').html(data);});setTimeout("news()", 180000);}$(document).ready(function() {//in here we put the first call to the breaking news script:setTimeout("news()", 180000);});</script></head><body>//other page elements<div id="breaking-news"></div>//more page elements</body></html>

  6. That's where I would put the script, yeah. When you upload the jQuery library, either rename it jquery.js on the server, or change the path where it is linked to appropriately.NB: You don't need to include the breaking-news.php script.

  7. This sounds like a job for JavaScript. You can set behaviours to happen when certain events occur, such as when the user hits a button to perform the addition or when the field where they input the second number loses focus.Here is the general idea:<html><head><title>Addition</title><script type="text/javascript">function add_em() {first = document.getElementById("first");second = document.getElementById("second");output = document.getElementById("output");output.value = parseInt(first.value)+parseInt(second.value);}</script></head><body><input type="text" size="5" id="first" value="" /><input type="text" size="5" id="second" value=""/><input type="button" value="add" onclick="add_em()" /><input type="text" size="10" id="output" value="" /></body></html>

  8. At a glance, note that you can't have more than one element with the same id, and you have 4 inputs with id NumbersOnly. This can cause unexpected behaviour. Perhaps name them 1_NumbersOnly and check if the that the id contains NumbersOnly as a string by using something like JavaScript's strstr or PHP's preg_match methods.

  9. You will need to find a way of keeping track of how many tds you have filled in each row, and only end the row and make a new one when you're at 5. At present, you are creating a new row for each database row, which isn't what you want.

  10. This line here is wrong:

    echo '<td>' . '<img Class="portlogo"' . ' ' . 'src="' . $row["image1"] . '"/>' . '<br>' . $row["client"] . '<br>' . $row["description"] . '</td>';

    Every time you use <br>, you get a new line, so all the data is displayed vertically. You need to wrap each fetched value in its own td:

    echo '<td>' . '<img Class="portlogo"' . ' ' . 'src="' . $row["image1"] . '"/>' . '</td><td>' . $row["client"] . '</td><td>' . $row["description"] . '</td>';

    Even then there are only 3 things being fetched from the database, so each row will only be 3 columns wide.

  11. Hi!Yes! Ajax Is Best For It...But U Can Set It To Javascript Too.Try This Code:
    <html><head><script>// Check Both Function...// These Are Calling Each Other After Every 5000:(5sec).// First Time U'll Have To Call: function setText();// Then It'll Start Loop// It'll Call function Autorefresh()// Then AutoRefresh Will Call Bach setText();// Like That Your Loop Will Be Start.// I Don't Know Y It's Not Working On I.E 6 :S But Google Chrome.function setText(){     keywords = ["saturday", "sunday", "monday", "tuesday", "wednesday", "friday"];     keyword = keywords[Math.floor(Math.random()*keywords.length)];     document.getElementById("mydiv").innerHTML=keyword;     AutoRefresh();}function AutoRefresh() {     setTimeout('setText()',1000);}</script></head><body>	<div id="mydiv" style="background: #ccc; padding: 10px; font: bold 14px arial;">		<script>setText();</script>	</div></body></html>

    Um...while this is a workable example of how to use setTimeout, it doesn't exactly do what the OP specified.
  12. Oh, I see. Well, the jQuery syntax looks like this:

    $.get('breaking-news.php', {}, function(data) {$('breaking-news').html(data);});

    $.get calls the ajax get method of the jQuery object. The first value in quotes is the server side script. Between the curly braces you can put any parameters you need to send. For example, if you needed to send a userid and say a sessionid, it might look like: {'userid' : userid, 'sessionid' : <?php echo sessionid(); ?>}. The last part of the first line is the function you want to fire when the onreadystate = 200 (i.e. when the request and return have been successfully made). The 'data' parameter holds the response data from the php script. The next line finds an element with id 'breaking-news' and sets its innerHTML to the response data.That relies on breaking-news.php returning HTML in a display-ready format.You would time the function by doing something like:

    setTimeout("news()", 180000);

    So you need to wrap the ajax fetching script in a function called news and recursively call itself every 180000 ms:

    function news() {$.get('breaking-news.php', {}, function(data) {$('breaking-news').html(data);});setTimeout("news()", 180000);}

    To use jQuery you need to DL the latest build, upload it to your server and link to it as you would any other javascript file. To make events fire when all the elements of the page are loaded, you use this syntax:

    $(document).ready(function() {//in here we put the first call to the breaking news script:setTimeout("news()", 180000);});

    So the whole shebang looks like:

    <script type="text/javascript" src="jquery.js"></script><script type="text/javascript">function news() {$.get('breaking-news.php', {}, function(data) {//either process the return data or stick it straight in its placeholder div$('breaking-news').html(data);});setTimeout("news()", 180000);}$(document).ready(function() {//in here we put the first call to the breaking news script:setTimeout("news()", 180000);});</script>

    I'm a big proponent of jQuery, because it makes a lot of things really simple and I like the syntax. Note that this code is untested, by the way, and that if your php script doesn't return the content in a way that is ready to display then you will need to process it where indicated.

  13. Out of curiosity Suzie, what function library/libraries are you using? The syntax for that Ajax function is similar to but not jQuery, I think. Definitely it looks a lot easier than vanilla JavaScript.

  14. I don't really understand your difficulty, dsonesuk. The div in the td has id 'user'. This div has the background style:background: url('../images/icons/scripts/user.png') no-repeat;The problem is that this div isn't the full height of the td it's nested in. I reckon a line-height that matches that of the png image will fix matters.Am I missing some other subtlety?

×
×
  • Create New...