www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-02-2009, 10:09 PM
    mattwidge mattwidge is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 33
    Angry Flagging

    I am making a web-app that has flagging in it. I've got that working, however, it doesn't maintain through a refresh (which happens every 20 seconds or so). How do I make it maintain through a refresh.

    Here's a stripped-down version of my code:
    HTML Code:
    <html>
    <head>
    <script type="text/JavaScript">
    function load() {
      window.setTimeout('window.location="display.php"; ',<?php echo $u['refresh']; ?>+"000");
    }
    function flag(id,btn) {
    var divid = id;
    var abtn = btn;
      document.getElementById(divid).style.background="#F0D7D7 url('display-bg-flagged.png') repeat-x";
      document.getElementById(btn).href="javascript:unflag('"+divid+"','"+abtn+"')";
      document.cookie = 'flag'+divid+'=true; expires=; path=/';
    }
    function unflag(id,btn) {
    var divid = id;
    var abtn = btn;
      document.getElementById(divid).style.background="#F0F0F0 url('display-bg.png') repeat-x";
      document.getElementById(btn).href="javascript:flag('"+divid+"','"+abtn+"')";
      createCookie("flag"+id,"",-1);
    }
    </script>
    </head>
    <body onLoad='load()'>
    <?php
    $user = $_COOKIE["logged-in"];
    $posts = $u['posts'];
    
      $result = mysql_query("select * from visitordata where user='".$_COOKIE['logged-in']."' order by id desc limit $posts");
      //the while loop
      $id=$_GET['id']; 
    
      echo "<div id=\"feedback\">";
    
      while($r=mysql_fetch_array($result))
      {
        echo "<div class=\"post\" id=\"".$r['id']."\" name=\"flag\" style=\"background:#F0F0F0 url(display-bg-flagged.png) repeat-x;\">";
        echo "<div class=\"info\"><a href=\"delete.php?delid=".$r['id']."\" title=\"Delete Feedback\"><img src=\"delete.png\" border=\"0\"></a> ";
        echo "<a href=\"javascript:flag('".$r['id']."','flagbtn".$r['id']."');\" title=\"Flag Feedback\" id=\"flagbtn".$r['id']."\"><img src=\"flag.png\" border=\"0\"></a>";
        echo " | <div class=\"time\">".$r['time']."</div> | <div class=\"name\">".$r['name']."</div> | <div class=\"location\">".$r['location']."</div> | <a href=\"http://".$r['ip_address']."\">".$r['ip_address']."</a></div>";
        echo "<a href=\"mail.php?mailid=".$r['id']."\" title=\"Email Feedback\"><img src=\"email.png\" border=\"0\"></a> <a href=\"block.php?ip=".$r['ip_address']."&user=".$_COOKIE['logged-in']."\"><img src=\"block.png\" border=0></a> | <div class=\"message\">".$r["message"]."</div></div></div>";
      }
    
      echo "</div>";
    ?>
    </body>
    </html>
    the variables like $r['xxxxx'] get info from a MySQL database.
    Reply With Quote
      #2  
    Old 11-03-2009, 11:50 AM
    omnicity omnicity is offline
    Registered User
     
    Join Date: Jan 2005
    Posts: 215
    I don't think I understand what you mean by 'flagging'
    Reply With Quote
      #3  
    Old 11-03-2009, 01:33 PM
    Declan1991 Declan1991 is offline
    Moderator
     
    Join Date: Aug 2007
    Posts: 2,699
    Refresh the page? Cookies or GET variables.
    __________________
    If I have helped
    Quote:
    Great wit and madness are near allied, and fine a line their bounds divide.
    Reply With Quote
      #4  
    Old 11-04-2009, 03:43 AM
    mattwidge mattwidge is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 33
    It's kinda hard to explain it, but I'll try my best.

    The PHP while continually loops until all the relevant data has been collected from a MySQL database. Each time it loops, it creates a DIV:
    Code:
    echo "<div class=\"post\" id=\"".$r['id']."\" name=\"flag\" style=\"background:#F0F0F0 url(display-bg.png) repeat-x;\">";
    (the $r['id'] gets the ID of the MySQL row)

    When I press the flag button:
    Code:
        echo "<a href=\"javascript:flag('".$r['id']."','flagbtn".$r['id']."');\" title=\"Flag Feedback\" id=\"flagbtn".$r['id']."\"><img src=\"flag.png\" border=\"0\"></a>";
    the background image of that specific DIV changes (see javascript code).

    My question is: when I 'flag' a DIV, the background changes, but when the page automatically refreshes, it returns to the original color. But I want it to STAY on the new color.
    Reply With Quote
      #5  
    Old 11-04-2009, 03:51 AM
    omnicity omnicity is offline
    Registered User
     
    Join Date: Jan 2005
    Posts: 215
    Declan has it 100% correct:
    either set a cookie when the flag button is pressed, and look for that same cookie every time the page is loaded,

    or else set a GET parameter, like when posting a form, and check for _that_ every time the page loads.

    I note that you are already setting cookies, so I presume you are aware that they are unreliable?
    Reply With Quote
      #6  
    Old 11-05-2009, 12:15 AM
    mattwidge mattwidge is offline
    Registered User
     
    Join Date: Aug 2009
    Posts: 33
    How would I do that?

    I can set cookies using:
    Code:
    document.cookie = 'flag'+divid+'=true; expires=; path=/';
    However, I don't know how to delete cookies or how to read all the "flagxx" cookies that would have been set.
    Reply With Quote
      #7  
    Old 11-05-2009, 05:31 AM
    omnicity omnicity is offline
    Registered User
     
    Join Date: Jan 2005
    Posts: 215
    You would not need to delete a cookie if you did: flag= divid
    Just set it to null if nothing is selected.

    Reading cookies is pretty easy, and there are plenty of tutorials online, but a little too much for me to go into now.
    Reply With Quote
    Reply

    Bookmarks

    Tags
    flag, maintain, php, refresh, variable


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 06:52 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.