Hi Forum,

I am trying to create a drop down menu using PHP that will assign a value to a Cookie.

I'm not sure how to script something to do this, but I am providing an example
of the code i am trying to use. I would appreciate it if someone could show me
the correct way to write a code that will assign the cookie "color" value.

I think my problem lies in the <input> part and possibly other areas.

Thanks 4 any help on this..

<form name="ColorPage">
<select name="list"><option value="0" [selected]>Beige
<option value="setcookie("color", "1", time()+3600);">Red
<option value="setcookie("color", "2", time()+3600);">Yellow
<option value="setcookie("color", "3", time()+3600);">White
<option value="setcookie("color", "4", time()+3600);">Green
<option value="setcookie("color", "5", time()+3600);">Blue
</select>
<input type=button value="<-- Select Page Color" onclick="color(color.list.options[color.list.selectedIndex].value)">
</form>

    PHP is a server-side language. You can't execute PHP code from the client-side without using something along the lines of AJAX.

    In this case, you'd want some client-side scripting (such as JavaScript) to set a cookie.

      Thanks for the response...

      Is it possible to assign a Variable on the client side and have this variable
      assigned to a cookie? eg. $var="user input" <?php setcookie("color", "$var");

      Thanks for help on this..

        You will have to submit the form and then save the cookie.

          rowanparker's suggestion is certainly one way to do it, or you can also do it without a page refresh using some JavaScript.

            I appreciate the info brad and rowan,

            thanks. Is it possible to place php code inside a .js?

              Short answer, nope.
              Long answer, you can use AJAX if you like, that is prob the best way to do it.

                Ok, thanks for the fast response.. I will now resolve this.. All I am trying to do is assign a cookie variable by way of selection from the user to select a color page they desire. I was hoping to keep everything PHP, but I see this may not be possible. Thanks for you guys help, It's appreciated..

                  No problem.

                  Remember, if you do not require anymore assistance them mark this thread as resolved.

                    Write a Reply...