|
Post by votan on Mar 11, 2009 16:45:19 GMT -5
I need your help in doing some javascript. The script needs to remember the selection you've made in a dropdown list in a cookie... and when revisiting the site it should automatically reselect the previously chosen option and make it available to RB for further usage.
Like I have three options for the dropdown list. 1) english 2) german 3) dutch
While english is the default, when selecting german, the selection should be stored in a cookie and so, when revisitng the site, the dropdown should automatically be set to "german" and the selected language needs to be available to RB, to directly display the page in the selected language.
I have absolutely no idea about JS, so any help is really appreciated.
|
|
|
Post by Janet on Mar 11, 2009 16:49:20 GMT -5
|
|
|
Post by votan on Mar 11, 2009 17:00:11 GMT -5
Already tried that..... but because of absolutely no JS capabilities, I couldn't get it modified the way to make it work. And maybe someone can even do it with some ajax , so that selecting an option directyl submitts the chosen selection without the need to first click on a link to submit the selection?
|
|
|
Post by Brent on Mar 12, 2009 23:29:01 GMT -5
Sorry about the slow response. I missed this thread then had to research and test for a while. My code assumes you have enableCookies pasted at the end. Cls Call enableCookies Dim lang$(3) lang$(1) = "English" lang$(2) = "German" lang$(3) = "Dutch" lang$ = lang$(1)
[start] GoSub [lang_picker] HTML "<script type=""text/javascript""><!-- // always change lang on page load document.body.onload = function() { chglang.click(); }; // get saved lang var lang = getCookie('lang'); // if it was saved, change the list selection if (lang) { for (var i = 0; i < langs.length; i++) { if (langs.options.text == lang) { langs.options.selected = true; break; } } } //--></script>" Wait ' display list and button, set JS vars [lang_picker] ListBox #langs, lang$(), 1 #langs setid("langs") Button #chglang, "Change", [change_lang] #chglang setid("chglang") HTML "<script type=""text/javascript""><!-- var langs = document.getElementById('langs'); var chglang = document.getElementById('chglang'); // auto-submit when selection changes langs.onchange = function() { chglang.click(); }; //--></script>" Return ' when the "change" button is clicked [change_lang] lang$ = #langs selection$() Cls Call enableCookies HTML "<script type=""text/javascript""><!-- // save new selection setCookie('lang', '"+lang$+"', '', days(30)); //--></script>" GoSub [lang_picker] #langs select(lang$) print print "I speak ";lang$ Wait HTH
|
|
|
Post by votan on Mar 13, 2009 18:06:10 GMT -5
Wow, cool, thank you! Will try to implement it into my code asap. Is there maybe a way to do it without using a submit button at all?
|
|
|
Post by Brent on Mar 16, 2009 15:08:20 GMT -5
I believe the only option you have, if you use my code, is to hide the button using CSS.
|
|
|
Post by kokenge on Oct 3, 2009 9:31:38 GMT -5
If anyone is interested, Mozilla Firefox holds the cookies in a SQLite table here: C:\Documents and Settings\dan\Application Data\Mozilla\Firefox\Profiles\r5nqzi25.default\cookies.sqlite
The name of the table is : moz_cookies
You need to use another browser like Opera to look at it because Firefox locks the DB.
If you don't have a SQLite management tool, you can generate a RB program to look at it using RBgen..
Just some info... Have a great day.. Dan
|
|