38 users online (0 members and 38 guests)  


  Results 1 to 5 of 5

Related

  1. Replies: 1
  2. Dynamic drop downs using cookies to store    Forum: Javascript Forum
    Replies: 0
  3. Replies: 2
  4. Jump Menu covers drop down menu    Forum: HTML Forum
    Replies: 1
  5. Setting cookies to remember drop down list    Forum: Website Scripts Forum
    Replies: 3
  1. #1
    jylaj's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2007
    Posts
    1

    cookies and drop down menu

    hi,
    I am new in working with cookies.So if anyone can help mi please do
    this is the problem:
    I have a script prva.php that has a drop down menu in which there are various values to select.The thing that i want to do is that to remebrer the selected value from the drop down menu so that the next time a person visits this page the value he selected the previous time from the drop down menu would be selected now instead the default(nothing selected ).
    the problem is I don't know what to put instead the red letters $Jazik because I tried doing $_POST["Jazik"] and $_POST["Jazik"] but this doesn't work also

    The code for prva.php is:

    Code:
    <?php
    //za cookie
    if (isset($_COOKIE['Jaz']))
        {
            echo "Postaveno e cookie, ".$_COOKIE['Jaz']."! Ajt cao!";
        }
        else
        {
            setcookie("Jaz", $Jazik, time()+60*60*24*30); 
        }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>356 - Речник</title>
    <style type="text/css">
    .style5 {
        color: #16A8CD;
        font-weight: bold;
    }
    .style7 {color: #16A8CD; font-weight: bold; font-size: 12px; }
    </style>
    <SCRIPT TYPE="text/javascript">
    
    function submitenter(myfield,e)
    {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    
    if (keycode == 13)
       {
       myfield.form.submit();
       return false;
       }
    else
       return true;
    }
    
    </SCRIPT>
    </head>
    <body>
    <?php 
    require('header.inc');
    ?>
    <table cellspacing="0" cellpadding="0" width="99%" border="0">
    <form  name="Meni" action="vtora_konecna.php" method="POST"> 
    <tr>
        <td height="25"> </td>
    </tr>
          
    <tr>
        <td width="44%" align="center" valign="top" bordercolor="#00FFFF" class="A-Text-BG" id="Recnik11_Td4">
        <div align="right">
        <p><span class="style5">ЈАЗИК</span> 
                <select name="Jazik" id="Jazik" style="width:25%;height:inherit" >
            
            <option selected="selected" value="none"> </option>
            <?php if (isset($_COOKIE['Jaz']) && $_COOKIE['Jaz'] == 'me')
                     {echo "<option value='me' selected> Mакедонски-Англиски </option>";} 
                  else
                      {echo "<option value='me'> Mакедонски-Англиски </option>";} ?>
            <?php if (isset($_COOKIE['Jaz']) && $_COOKIE['Jaz'] == 'em') 
                      {echo "<option value='em' selected> Англиски-Македонски </option>";}
                  else
                      {echo "<option value='em'> Англиски-Македонски </option>";}?>
            <?php if (isset($_COOKIE['Jaz']) && $_COOKIE['Jaz'] == 'md') 
                     {echo "<option value='md' selected> Македонски-Германски </option>";}
                  else
                  {echo "<option value='md'> Македонски-Германски </option>";}?>
            <?php if (isset($_COOKIE['Jaz']) && $_COOKIE['Jaz'] == 'dm') 
                    {echo "<option value='dm' selected> Германски-Македонски </option>";}
                  else
                  {echo "<option value='dm'> Германски-Македонски </option>";}?> 
    </p>
    </div>
    </td>
    </tr>
    
    <tr>
             <td height="25"> </td>
    </tr>
        
    <tr>
    <td>
        <p align="center"><span class="style5" >Збор за превод:</span> 
        <input name="word" type="text"  size="50"  />
        </p>
              
        <div align="right">
        <input type="hidden" value=Пребарај" style="style5" />
        </div>
              
    <p>&nbsp;</p>
    </td>
    </tr>
      
    <tr>
         <td height="25"></td>
    </tr>
    
    </form> 
    </table>
    
    
    <table width="948" height="51">
     <tr>
         <td height="21" class="style7">Збор на денот: </td>
         <td>
         <p><span class="style7" >Најпребарувани зборови:</span></p>
         </td>
     </tr>
    <tr>
    <td width="573" height="5"></td>
    <td width="363">
    
    <?php
    $connection=mysql_connect("localhost","root") or die("Пробај пак.");
    $db=mysql_select_db("mysql",$connection) or die("Пробај пак.");
    $sql = "SELECT zbor FROM top_zborovi";
    $sql_result=mysql_query($sql,$connection)or die(mysql_error($connection));
    $broj_rez=mysql_num_rows($sql_result);
    if ($broj_rez==0) {echo "nema redovi" ;}
        else
        {
            for($i=0;$i<$broj_rez;$i++)
            {
                if ((($i%10)==0)&&($i!=0)) {print "<br/>";}
                $row=mysql_fetch_row($sql_result);
                $Zbor=$row[0];
                echo "<a href=\"vtora_konecna.php?zbor=".$Zbor."\">".$Zbor."</a>";
                echo " ";
            }//fori
        }//else
        
    ?></td>
    </tr>
    </table>
    
    
    <p>&nbsp;</p>
    <p>
      <?php 
    require('footer.inc');
    ?>
    </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp; </p>
    </body>
    </html>
    Last edited by HTML; 03-08-2012 at 11:59 AM. Reason: Added code tags

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: cookies and drop down menu

    I'm having a bad day today, so apologies if this doesn't work!

    Take out the selected="selected" from the first option - if none of the other options are set to selected it will default to the first one anyway, and if there are two you can't rely on browser behaviour to select the right one.

    On the page that the form submits to, just set $_COOKIE['Jaz'] = $_POST['Jazik']
    That should be it.

  3. #3
    sajosh's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2007
    Posts
    2

    Re: cookies and drop down menu

    hi, i'm looking for the same thing but using javascript. would either of you be able to translate that to js? i'm a non-coder.

    what i want to do is save user input via cookies which would be then listed in a drop down. so, suppose a user enters value1, submits it, then enters value 2, submits it, then enters value3, and submits. after each submit the dropdown (which would be under the input area. so would that be a combobox?) on the fourth use, the user selects value2 from teh dropdown and submits, on the fifth use, selects value1 and submits it.

    is this possible in js?

  4. #4
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: cookies and drop down menu

    sajosh - you need to post your request in the JavaScript forum, this area's full of php!

  5. #5
    pehden's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2007
    Posts
    2

    Re: cookies and drop down menu

    How can I get this to store in the cookie then load from the cookie on areturning visit.

    <?php
    $set = $_GET['set'];
    if(isset($_COOKIE['style']))
    $set = $_COOKIE['style'];
    else
    Echo "Welcome! You have been showed the default style!";
    Echo "Welcome back chosen style is restored to ".$_COOKIE['style']."!";
    switch ($set)
    {
    case 1:
    $thestyle = "style";
    break;
    case 2:
    $thestyle = "other";
    break;
    default:
    $thestyle = "style";
    break;
    setcookie('style', $set, $inTwoMonths);
    }
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
    <html xmlns="">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" media="screen" href="<?php echo($thestyle);?>.css" >
    <title>LOL</title>
    <body>
    <div class="box">Test Word</div>
    <a href="lol.php?set=1">Style Sheet One</a>
    <a href="lol.php?set=2">Style Sheet Two</a>
    </body>
    </html>



Tags for this Thread