SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Saving information across page views (was: Important)

    Hi,

    https://khan.byu.edu/~pb88/floorTile/test.php

    What I need: When I click on each square, the color changes. Now when I hit the submit button, it should save those changes so that when I visit again, it should display all those colors in the boxes. The following is the source code:

    <html>
    <style>
    .address{
    margin-left: 128px;
    margin-top: 0px;
    float:right;

    }
    .header{color:green;}
    .containers
    {
    float:left;margin-top: 0px;
    }
    .changes
    {
    float:left;
    }
    </style>

    <!--Submit Changes button-->
    <body bgcolor = "#FFFFCC">
    </body>
    <form method= "POST">
    <input type = "submit" value ="Submit">
    </form>
    <?php
    $rows = 100;
    $cols = 25;
    $cellWidth = 38;
    $cellHeight = 25;
    $style = 'margin-right: 100px; margin-top: 0px; border-color: blue; border-width: 1px; border-style: solid; font-size: 13px;';
    $tableWidth = $cellWidth * $cols;
    $eachCell;
    echo '<table width="'.$tableWidth .'" border="0" cellspacing="1" cellpadding="10">';

    //*****************************************Generating Squares******************************************/

    for ($i = 0; $i < $rows; $i++)
    {
    echo '<tr>';
    for ($j = 0; $j < $cols; $j++)
    {
    $eachCell = '<td width="'.$cellWidth.'" height="'.$cellHeight.'" style="'.$style.'" id="'.$countName.'">&nbsp;</td>';
    echo $eachCell;

    }
    echo '</tr>';
    }
    ?>
    <script type="text/javascript">
    var flag;

    function setupGrid()
    {

    if (!document.getElementsByTagName) return;
    var cells = document.getElementsByTagName('td');
    for (var i=0; i < cells.length; i++)
    {
    cells[i].onmouseover = test;
    cells[i].onclick = Colorize;


    }

    }
    function test()
    {
    flag = 1;
    }
    var colorTable = Array('white', 'red','green','black');
    var curColor = 0;
    var cMax = colorTable.length - 1;

    //*****************************************************coloring the squares***************************//

    function Colorize()
    {


    if(flag ==1)
    {
    curColor=0;
    flag=0;
    }
    this.style.backgroundColor = colorTable[curColor];
    curColor++;
    temp = curColor;
    if (curColor > cMax) curColor = 0;
    }



    window.onload = setupGrid;
    </script>
    <?php
    ?>


    </html>


    Can anyone help?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,815
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You don't have the code there to save the cookie with the colour info in it so that you can read it back next time.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hey

    Quote Originally Posted by felgall
    You don't have the code there to save the cookie with the colour info in it so that you can read it back next time.
    I know I have to have a cookie info. But I am not able to figure out how to do it.
    Can you help?

    Thanks.

  4. #4
    SitePoint Enthusiast pentapenguin's Avatar
    Join Date
    Aug 2005
    Location
    GA, USA
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

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