PDA

View Full Version : dropdown box value activates a setCookie


motormichael12
10-21-2006, 11:58 PM
I need a script that uses the thing like "if value="6" setcookie(i know what goes here)"

It needs to be in a login form, where if I have a dropdown box and they select a certain time and the cookie for keeping them logged in stays active until then.

I know how to do the setCookie part but I need help setting up the "if" script.

Thanks

jscheuer1
11-04-2006, 08:07 AM
function set_the_cookie(v){
if (v==1)
setcookie(you know what goes here);
else if (v==2)
setcookie(you know what goes here);
else if (v==3)
setcookie(you know what goes here);
else if (v==4)
setcookie(you know what goes here);
}

<select onchange="set_the_cookie(this.selectedIndex);">

The select will return 0 through however many options it has minus one to the 'set_the_cookie()' function when its value is changed by the user's selection. I left 0 out of the function because I thought that 0 means 0, no cookie. You can also have a final:

else
do something here if none of the conditions are met

if you like.

motormichael12
11-05-2006, 02:40 AM
okie... will that work in php as well?

and is there any editing required besides the (you know what goes here) parts and the "do something here if none of the conditions are met" part?

jscheuer1
11-05-2006, 03:43 AM
If you knew this was PHP and wanted it in that language, you should have posted in that forum as, you probably would have gotten to a resolution more quickly there. I don't mind though and, who knows, this background might still be of help to you. PHP is not my strong suit but, I do know a thing or two about it. It can interact with javascript, which is the language I used above but, javascript isn't secure and is useless if the user has it disabled or unavailable. However, if security of a particular operation is unimportant and there is a fall-back method for non-javascript users, javascript can streamline and enhance operations for PHP while at the same time taking some of the load off of the server. I also know that these determinations and actions can be made and performed in PHP but, probably not on a dynamic basis. The page or form would need to (most likely) be submitted before they can be carried through. The syntax and code space are different but, the logic is identical.

One other thing, javascript alone cannot set a server-side cookie if that is your objective, but it can set a client side cookie.