Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    New Coder
    Join Date
    Nov 2006
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    Okay, I wasn't as close as I thought. Js is still just echoing whatever php is outputting.

    Code:
    function handleJoblog() {
      if(httpjob.readyState == 4) {
        var response = httpjob.responseText;
    	if(response=="Update! ") {
        document.getElementById('bar').innerHTML = response;
    	document.getElementById('bar').style.color = "red"
    	}
    	if(response!="Update! ") {
        document.getElementById('bar').innerHTML = response;
    	document.getElementById('bar').style.color = "yellow"
    	}
      }
    }
    The above code outputs in yellow whether there is new data or not.

    Here is the php:
    Code:
    $total_job_log_entries = ceil(mysql_num_rows(mysql_query("SELECT id FROM job_log WHERE id > '1'")));
    if ($total_job_log_entries != $jle_old){
    $response = "Update! ";
    echo $response;
    echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
    }else{
    echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
    }

  2. #17
    New Coder
    Join Date
    Nov 2006
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    I couldn't get this to work either.
    Code:
      if(httpjob.readyState == 4) {
        var response = httpjob.responseText;
    	if(newdata == yes) {
        document.getElementById('bar').innerHTML = response;
    	document.getElementById('bar').style.color = "red"
    	}
    	if(response!="Update! ") {
        document.getElementById('bar').innerHTML = response;
    	document.getElementById('bar').style.color = "yellow"
    	}

    Code:
    $total_job_log_entries = ceil(mysql_num_rows(mysql_query("SELECT id FROM job_log WHERE id > '1'")));
    if ($total_job_log_entries != $jle_old){
    ?>
    <script type="text/javascript">
    var newdata=yes;
    </script>
    <?php
    //$response = "Update! ";
    //echo $response;
    echo $response . "Total number of job log entries: " . $total_job_log_entries . "<br>";
    }else{
    echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
    }
    $HTTP_SESSION_VARS["jle_old"] = $total_job_log_entries;

  3. #18
    New Coder
    Join Date
    May 2008
    Posts
    80
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Netscape

    Matthew you're completely screwing your code. that javascript line doesn't doesn't help much and still trying clientside evualation .
    where comes this newdata from?
    Assuming the server returns update or noupdate. we can than return to the switch statement
    switch(response) {
    case update:
    document.getElementById('bar').innerHTML = response;
    document.getElementById('bar').style.color = "red"
    break;
    default :
    document.getElementById('bar').innerHTML = response;
    document.getElementById('bar').style.color = "yellow"
    }
    when done that you can return your whole string and do a substring search for noupdate
    Last edited by tfit; 03-22-2010 at 09:53 PM. Reason: added information

  4. #19
    New Coder
    Join Date
    Nov 2006
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    That's the problem. PHP will output either "blah 123" or "Update! blah 124". Js is simply echoing what php is outputing. I don't want to include the word "Update".

    If it were all php I would do this:

    Code:
    session_start();
    
    //job log entries
    $total_job_log_entries = '0';
    $total_job_log_entries = ceil(mysql_num_rows(mysql_query("SELECT id FROM job_log WHERE id > '1'")));
    if ($total_job_log_entries != $jle_old){
    //new data
    echo "<font color='red'>Total number of job log entries: " . $total_job_log_entries . "</font><br>";
    }else{
    //same old data
    echo "<font color='yellow'>Total number of job log entries: " . $total_job_log_entries . "</font><br>";
    }
    $HTTP_SESSION_VARS["jle_old"] = $total_job_log_entries;
    mysql_close();
    All I need is a way to tell Js I have new data so I can make the background for that table cell flash or briefly change color or something.

  5. #20
    New Coder
    Join Date
    Nov 2006
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    GOT IT!!!!!!
    Added this function on the client side:
    Code:
    function blinkIt() {
     if (!document.all) return;
     else {
       for(i=0;i<document.all.tags('blink').length;i++){
          s=document.all.tags('blink')[i];
          s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
       }
     }
    }
    And this on the server side:
    Code:
    if ($total_job_log_entries != $jle_old){
    $response = "Update! ";
    echo "<blink>Total number of job log entries: " . $total_job_log_entries . "</blink><br>";
    }else{
    echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
    }

  6. #21
    New Coder
    Join Date
    May 2008
    Posts
    80
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by matthewst View Post
    GOT IT!!!!!!
    Added this function on the client side:
    Code:
    function blinkIt() {
     if (!document.all) return;
     else {
       for(i=0;i<document.all.tags('blink').length;i++){
          s=document.all.tags('blink')[i];
          s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
       }
     }
    }
    And this on the server side:
    Code:
    if ($total_job_log_entries != $jle_old){
    $response = "Update! ";
    echo "<blink>Total number of job log entries: " . $total_job_log_entries . "</blink><br>";
    }else{
    echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
    }
    you're introducing different viewpoints at times , but i'm glad you got it working

  7. #22
    New Coder
    Join Date
    Nov 2006
    Posts
    48
    Thanks
    3
    Thanked 1 Time in 1 Post
    Yeah, I'm still learning Js. Thanks for the help.



    How do I mark this resolved?
    Last edited by matthewst; 03-23-2010 at 01:11 PM.

  8. #23
    New Coder
    Join Date
    May 2008
    Posts
    80
    Thanks
    3
    Thanked 3 Times in 3 Posts
    I have to search for that from time to time too Anyway go to your first post, edit, advanced, title and there you can change status
    Last edited by tfit; 03-23-2010 at 01:39 PM.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •